mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.5 KiB

  1. /* ROCK Linux Wrapper for getting a list of created files
  2. *
  3. * --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. *
  5. * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. * Please add additional copyright information _after_ the line containing
  7. * the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. * the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. *
  10. * ROCK Linux: rock-src/misc/tools-source/fl_wrapper_open.c
  11. * ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version. A copy of the GNU General Public
  17. * License can be found at Documentation/COPYING.
  18. *
  19. * Many people helped and are helping developing ROCK Linux. Please
  20. * have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. * file for details.
  22. *
  23. * --- ROCK-COPYRIGHT-NOTE-END ---
  24. */
  25. extern int open(const char* f, int a, ...);
  26. int (*orig_open)(const char* f, int a, ...) = 0;
  27. int open(const char* f, int a, ...)
  28. {
  29. struct status_t status;
  30. int old_errno=errno;
  31. int rc;
  32. handle_file_access_before("open", f, &status);
  33. if (!orig_open) orig_open = get_dl_symbol("open");
  34. errno=old_errno;
  35. #if DEBUG == 1
  36. fprintf(stderr, "fl_wrapper.so debug [%d]: going to run original open() at %p (wrapper is at %p).\n",
  37. getpid(), orig_open, open);
  38. #endif
  39. if (a & O_CREAT)
  40. {
  41. va_list ap;
  42. mode_t b = 0;
  43. va_start(ap, a);
  44. b = va_arg(ap, mode_t);
  45. va_end(ap);
  46. rc = orig_open(f, a, b);
  47. }
  48. else
  49. rc = orig_open(f, a);
  50. old_errno=errno;
  51. handle_file_access_after("open", f, &status);
  52. errno=old_errno;
  53. return rc;
  54. }
  55. extern int open64(const char* f, int a, ...);
  56. int (*orig_open64)(const char* f, int a, ...) = 0;
  57. int open64(const char* f, int a, ...)
  58. {
  59. struct status_t status;
  60. int old_errno=errno;
  61. int rc;
  62. handle_file_access_before("open64", f, &status);
  63. if (!orig_open64) orig_open64 = get_dl_symbol("open64");
  64. errno=old_errno;
  65. #if DEBUG == 1
  66. fprintf(stderr, "fl_wrapper.so debug [%d]: going to run original open64() at %p (wrapper is at %p).\n",
  67. getpid(), orig_open64, open64);
  68. #endif
  69. if (a & O_CREAT)
  70. {
  71. va_list ap;
  72. mode_t b = 0;
  73. va_start(ap, a);
  74. b = va_arg(ap, mode_t);
  75. va_end(ap);
  76. rc = orig_open64(f, a, b);
  77. }
  78. else
  79. rc = orig_open64(f, a);
  80. old_errno=errno;
  81. handle_file_access_after("open64", f, &status);
  82. errno=old_errno;
  83. return rc;
  84. }