| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.10

 

make_dir

#include "sfldir.h"
int
make_dir (
    const char *path_to_create)

Synopsis

Create a new directory. Returns 0 if the directory was created; -1 if there was an error. Under Windows and OpenVMS, accepts directory names with '/'. Will create multiple levels of directory if required.

Source Code - (sfldir.c)

{
    char
        *path,
        *slash;
    int
        rc = 0;

    path = mem_strdup (path_to_create); /*  Working copy                     */
#if (defined (MSDOS_FILESYSTEM))
    strconvch (path, '/', '\\');
#endif

    /*  Create each component of directory as required                       */
    slash = strchr (path + 1, PATHEND); /*  Find first slash                 */
    FOREVER                             /*  Create any parent directories    */
      {
        if (slash)
            *slash = '\0';              /*  Cut at slash                     */

        if (!file is directory (path))
          {
#if (defined (__UNIX__) || defined (__VMS_XOPEN) || defined (__OS2__))
            rc = mkdir (path, 0775);    /*  User RWE Group RWE World RE      */

#elif (defined (WIN32))
            if (CreateDirectory (path, NULL))
                rc = 0;
            else
                rc = -1;

#elif (defined (MSDOS_FILESYSTEM))
#   if (defined (__DJGPP__))
            rc = mkdir (path, 0775);    /*  User RWE Group RWE World RE      */
#   else
            rc = mkdir (path);          /*  Protection?  What's that?        */
#   endif
#else
            rc = -1;                    /*  Not a known system               */
#endif
            if (rc)                     /*  End if error                     */
                break;
          }
        if (slash == NULL)              /*  End if last directory            */
            break;
       *slash = PATHEND;                /*  Restore path name                */
        slash = strchr (slash + 1, PATHEND);
      }
    mem_strfree (&path);
    return (rc);
}

| << | < | > | >> iMatix Copyright © 1996-99 iMatix Corporation