Annotation of coherent/g/usr/bin/pax/port.c, revision 1.1.1.1

1.1       root        1: /* $Source: /src386/usr/bin/pax/port.c,v $
                      2:  *
                      3:  * $Revision: 1.1 $
                      4:  *
                      5:  * port.c - These are routines not available in all environments. 
                      6:  *
                      7:  * DESCRIPTION
                      8:  *
                      9:  *     The routines contained in this file are provided for portability to
                     10:  *     other versions of UNIX or other operating systems (e.g. MSDOS).
                     11:  *     Not all systems have the same functions or the same semantics,
                     12:  *     these routines attempt to bridge the gap as much as possible.
                     13:  *
                     14:  * AUTHOR
                     15:  *
                     16:  *     Mark H. Colburn, NAPS International ([email protected])
                     17:  *     John Gilmore (gnu@hoptoad)
                     18:  *
                     19:  * Sponsored by The USENIX Association for public distribution. 
                     20:  *
                     21:  * Copyright (c) 1989 Mark H. Colburn.
                     22:  * All rights reserved.
                     23:  *
                     24:  * Redistribution and use in source and binary forms are permitted
                     25:  * provided that the above copyright notice is duplicated in all such 
                     26:  * forms and that any documentation, advertising materials, and other 
                     27:  * materials related to such distribution and use acknowledge that the 
                     28:  * software was developed * by Mark H. Colburn and sponsored by The 
                     29:  * USENIX Association. 
                     30:  *
                     31:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     32:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     33:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     34:  *
                     35:  * $Log:       port.c,v $
                     36:  * Revision 1.1  92/08/28  08:02:56  bin
                     37:  * Initial revision
                     38:  * 
                     39:  * Revision 1.1  89/02/14  16:48:39  jep
                     40:  * Initial revision
                     41:  * 
                     42:  * Revision 1.1  88/12/23  18:02:29  mark
                     43:  * Initial revision
                     44:  * 
                     45:  */
                     46: 
                     47: #ifndef lint
                     48: static char *ident = "$Id: port.c,v 1.1 92/08/28 08:02:56 bin Exp Locker: bin $";
                     49: static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
                     50: #endif /* ! lint */
                     51: 
                     52: 
                     53: /* Headers */
                     54: 
                     55: #include "pax.h"
                     56: 
                     57: 
                     58: /*
                     59:  * Some computers are not so crass as to align themselves into the BSD or USG
                     60:  * camps.  If a system supplies all of the routines we fake here, add it to
                     61:  * the list in the #if !defined()'s below and it'll all be skipped. 
                     62:  */
                     63: 
                     64: #if !defined(mc300) && !defined(mc500) && !defined(mc700) && !defined(BSD)
                     65: 
                     66: /* mkdir - make a directory
                     67:  *
                     68:  * DESCRIPTION
                     69:  *
                     70:  *     Mkdir will make a directory of the name "dpath" with a mode of
                     71:  *     "dmode".  This is consistent with the BSD mkdir() function and the
                     72:  *     P1003.1 definitions of MKDIR.
                     73:  *
                     74:  * PARAMETERS
                     75:  *
                     76:  *     dpath           - name of directory to create
                     77:  *     dmode           - mode of the directory
                     78:  *
                     79:  * RETURNS
                     80:  *
                     81:  *     Returns 0 if the directory was successfully created, otherwise a
                     82:  *     non-zero return value will be passed back to the calling function
                     83:  *     and the value of errno should reflect the error.
                     84:  */
                     85: 
                     86: #if __STDC__
                     87: 
                     88: int mkdir(char *dpath, int dmode)
                     89: 
                     90: #else
                     91:     
                     92: int mkdir(dpath, dmode)
                     93: char           *dpath;
                     94: int             dmode;
                     95: 
                     96: #endif
                     97: {
                     98:     int             cpid, status;
                     99:     Stat            statbuf;
                    100:     extern int      errno;
                    101: 
                    102:     if (STAT(dpath, &statbuf) == 0) {
                    103:        errno = EEXIST;         /* Stat worked, so it already exists */
                    104:        return (-1);
                    105:     }
                    106:     /* If stat fails for a reason other than non-existence, return error */
                    107:     if (errno != ENOENT)
                    108:        return (-1);
                    109: 
                    110:     switch (cpid = fork()) {
                    111: 
                    112:     case -1:                   /* Error in fork() */
                    113:        return (-1);            /* Errno is set already */
                    114: 
                    115:     case 0:                    /* Child process */
                    116: 
                    117:        status = umask(0);      /* Get current umask */
                    118:        status = umask(status | (0777 & ~dmode));       /* Set for mkdir */
                    119:        execl("/bin/mkdir", "mkdir", dpath, (char *) 0);
                    120:        _exit(-1);              /* Can't exec /bin/mkdir */
                    121: 
                    122:     default:                   /* Parent process */
                    123:        while (cpid != wait(&status)) {
                    124:            /* Wait for child to finish */
                    125:        }
                    126:     }
                    127: 
                    128:     if (TERM_SIGNAL(status) != 0 || TERM_VALUE(status) != 0) {
                    129:        errno = EIO;            /* We don't know why, but */
                    130:        return (-1);            /* /bin/mkdir failed */
                    131:     }
                    132:     return (0);
                    133: }
                    134: 
                    135: 
                    136: /* rmdir - remove a directory
                    137:  *
                    138:  * DESCRIPTION
                    139:  *
                    140:  *     Rmdir will remove the directory specified by "dpath".  It is
                    141:  *     consistent with the BSD and POSIX rmdir functions.
                    142:  *
                    143:  * PARAMETERS
                    144:  *
                    145:  *     dpath           - name of directory to remove
                    146:  *
                    147:  * RETURNS
                    148:  *
                    149:  *     Returns 0 if the directory was successfully deleted, otherwise a
                    150:  *     non-zero return value will be passed back to the calling function
                    151:  *     and the value of errno should reflect the error.
                    152:  */
                    153: 
                    154: #if __STDC__
                    155: 
                    156: int rmdir(char *dpath)
                    157: 
                    158: #else
                    159:     
                    160: int rmdir(dpath)
                    161: char           *dpath;
                    162: 
                    163: #endif
                    164: {
                    165:     int             cpid, status;
                    166:     Stat            statbuf;
                    167:     extern int      errno;
                    168: 
                    169:     /* check to see if it exists */
                    170:     if (STAT(dpath, &statbuf) == -1) {
                    171:        return (-1);
                    172:     }
                    173:     switch (cpid = fork()) {
                    174: 
                    175:     case -1:                   /* Error in fork() */
                    176:        return (-1);            /* Errno is set already */
                    177: 
                    178:     case 0:                    /* Child process */
                    179:        execl("/bin/rmdir", "rmdir", dpath, (char *) 0);
                    180:        _exit(-1);              /* Can't exec /bin/rmdir */
                    181: 
                    182:     default:                   /* Parent process */
                    183:        while (cpid != wait(&status)) {
                    184:            /* Wait for child to finish */
                    185:        }
                    186:     }
                    187: 
                    188:     if (TERM_SIGNAL(status) != 0 || TERM_VALUE(status) != 0) {
                    189:        errno = EIO;            /* We don't know why, but */
                    190:        return (-1);            /* /bin/rmdir failed */
                    191:     }
                    192:     return (0);
                    193: }
                    194: 
                    195: #endif /* MASSCOMP, BSD */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.