home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / mkdir.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  115 lines

  1. /***
  2. *mkdir.c - make directory
  3. *
  4. *       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Defines function _mkdir() - make a directory
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifndef _MAC
  12.  
  13. #include <cruntime.h>
  14. #include <oscalls.h>
  15. #include <internal.h>
  16. #include <direct.h>
  17. #include <tchar.h>
  18.  
  19. /***
  20. *int _mkdir(path) - make a directory
  21. *
  22. *Purpose:
  23. *       creates a new directory with the specified name
  24. *
  25. *Entry:
  26. *       _TSCHAR *path - name of new directory
  27. *
  28. *Exit:
  29. *       returns 0 if successful
  30. *       returns -1 and sets errno if unsuccessful
  31. *
  32. *Exceptions:
  33. *
  34. *******************************************************************************/
  35.  
  36. int __cdecl _tmkdir (
  37.         const _TSCHAR *path
  38.         )
  39. {
  40.         ULONG dosretval;
  41.  
  42.         /* ask OS to create directory */
  43.  
  44.         if (!CreateDirectory((LPTSTR)path, (LPSECURITY_ATTRIBUTES)NULL))
  45.             dosretval = GetLastError();
  46.         else
  47.             dosretval = 0;
  48.  
  49.         if (dosretval) {
  50.             /* error occured -- map error code and return */
  51.             _dosmaperr(dosretval);
  52.             return -1;
  53.         }
  54.  
  55.         return 0;
  56. }
  57.  
  58. #else  /* _MAC */
  59.  
  60. #include <cruntime.h>
  61. #include <internal.h>
  62. #include <direct.h>
  63. #include <string.h>
  64. #include <errno.h>
  65. #include <macos\osutils.h>
  66. #include <macos\files.h>
  67. #include <macos\errors.h>
  68.  
  69. /***
  70. *int _mkdir(path) - make a directory
  71. *
  72. *Purpose:
  73. *       creates a new directory with the specified name
  74. *
  75. *Entry:
  76. *       char *path - name of new directory
  77. *
  78. *Exit:
  79. *       returns 0 if successful
  80. *       returns -1 and sets errno if unsuccessful
  81. *
  82. *Exceptions:
  83. *
  84. *******************************************************************************/
  85.  
  86. int __cdecl _mkdir (
  87.         const char *path
  88.         )
  89. {
  90.         /* ask OS to create directory */
  91.         HParamBlockRec hparamBlock;
  92.         char st[256];
  93.         OSErr osErr;
  94.  
  95.         if (!*path)
  96.         {
  97.             errno = ENOENT;
  98.             return -1;
  99.         }
  100.         strcpy(st, path);
  101.         hparamBlock.fileParam.ioNamePtr = _c2pstr(st);
  102.         hparamBlock.fileParam.ioVRefNum = 0;
  103.         hparamBlock.fileParam.ioDirID = 0;
  104.         osErr = PBDirCreateSync(&hparamBlock);
  105.         if (osErr) {
  106.             /* error occured -- map error code and return */
  107.             _dosmaperr(osErr);
  108.             return -1;
  109.         }
  110.  
  111.         return 0;
  112. }
  113.  
  114. #endif  /* _MAC */
  115.