Leaked source code of windows server 2003
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.

66 lines
1.6 KiB

  1. #ifndef _WIN32
  2. #ifndef _WINIO_HXX
  3. #define _WINIO_HXX
  4. #include <assert.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <sys/param.h>
  9. #include <fcntl.h>
  10. #include <stdlib.h>
  11. /* windows format parameters */
  12. #define _S_IFMT 0170000 /* file type mask */
  13. #define _S_IFDIR 0040000 /* directory */
  14. #define _S_IFCHR 0020000 /* character special */
  15. #define _S_IFIFO 0010000 /* pipe */
  16. #define _S_IFREG 0100000 /* regular */
  17. #define _S_IREAD 0000400 /* read permission, owner */
  18. #define _S_IWRITE 0000200 /* write permission, owner */
  19. #define _S_IEXEC 0000100 /* execute/search permission, owner */
  20. inline int _creat(const char *filename, int pmode)
  21. {
  22. int oflag=O_CREAT|O_TRUNC;
  23. if (pmode & _S_IWRITE)
  24. oflag |= O_RDWR;
  25. else if (pmode & _S_IREAD)
  26. oflag |= O_RDONLY;
  27. else {
  28. printf("ERROR: _creat called with unrecognised parameter!\n");
  29. assert(FALSE);
  30. }
  31. int fides = open(filename, oflag);
  32. fchmod(fides, S_IRUSR|S_IWUSR); // enable read/write by owner
  33. return fides;
  34. }
  35. inline int _close(int fildes)
  36. {
  37. return close(fildes);
  38. }
  39. inline int _chmod( const char *filename, int pmode )
  40. {
  41. mode_t unixmode=0;
  42. if (pmode & _S_IWRITE)
  43. unixmode |= (S_IWUSR|S_IWGRP|S_IWOTH|S_IRUSR|S_IRGRP|S_IROTH);
  44. else if (pmode & _S_IREAD)
  45. unixmode |= (S_IRUSR|S_IRGRP|S_IROTH);
  46. else
  47. {
  48. printf("ERROR: _chmod called with unrecognized parameter!\n");
  49. assert(FALSE);
  50. }
  51. return chmod(filename, pmode);
  52. }
  53. #define _getcwd getcwd
  54. #define _chdir chdir
  55. #define _unlink unlink
  56. #endif // ifdef _WINIO_HXX
  57. #endif // ifdef _WIN32