user/lib/libc/src/file/fd/open.c
/**
 * Opens a file and returns its descriptor.
 */
Opens a file and returns its descriptor.
Opens a file and returns its descriptor .
int open(const char *path, int oflag, ...) {
    char mode[3] = {' ', ' ', 0};
    if(oflag & O_RDWR) {
        mode[0] = 'w';
        mode[1] = '+';
    }
    else if(oflag & O_RDONLY) {
        mode[0] = 'r';
    } else if(oflag & O_WRONLY) {
        mode[0] = 'w';
    }
    FILE *f = fopen(path, mode);
    if(!f) {
        errno = ENOENT;
        return -1;
    }
    return fileno(f);
}
int open ( const char * path , int oflag , ... ) { char mode [ 3 ] = { ' ' , ' ' , 0 } ; if ( oflag & O_RDWR ) { mode [ 0 ] = ' ' ; mode [ 1 ] = ' ' ; } else if ( oflag & O_RDONLY ) { mode [ 0 ] = ' ' ; } else if ( oflag & O_WRONLY ) { mode [ 0 ] = ' ' ; } FILE * f = fopen ( path , mode ) ; if ( ! f ) { errno = ENOENT ; return -1 ; } return fileno ( f ) ; }
Opens a file and returns its descriptor.
Opens a file and returns its descriptor .
// convert flags field // open file // return its descriptor name