/*
 *              m k d i r
 *
 *   Unix compatible routine to create a directory
 *  (on a system that supports this such as the Miracle
 *  Systems hard disk).
 *
 *  Returns:
 *      success     0
 *      failure     -1   and sets errno (and if relevant) _oserr.
 *
 * AMENDMENT HISTORY
 * ~~~~~~~~~~~~~~~~~
 *  11 Jul 93   DJW   - Removed assumption that io_mkdir() sets _oserr.
 *
 *  26 Jan 94   DJW   - Changed definition slightly to allow for a second
 *                      parameter (which is not used). On Unix systems this
 *                      would be the mode to set on the directory.
 */

#define __LIBRARY__

#include <sys/stat.h>
#include <fcntl.h>
#include <qdos.h>
#include <errno.h>
#include <unistd.h>

int mkdir  ( const char * name, ... )
{
    int fd;
    int reply;

    /*
     *  First create a file of the desired name
     */
    if((fd = open( name, O_CREAT | O_RDWR))== -1) {
        return -1;
    }

    /*
     *  Now do the low level call to convert to directory
     */
    if( (reply=io_mkdir( getchid( fd ))) != 0) {
        (void) close( fd );
        /* Now delete the file we created */
        (void) unlink( name );
        _oserr = reply;
        errno = EOSERR;
        return -1;
    }
    (void) close( fd );
    return 0;
}

