[BACK]Return to fileio.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/fileio.c, Revision 1.58

1.58    ! kjell       1: /*     $OpenBSD: fileio.c,v 1.57 2005/10/17 14:54:03 kjell Exp $       */
1.50      kjell       2:
                      3: /* This file is in the public domain. */
1.10      niklas      4:
1.1       deraadt     5: /*
1.7       millert     6:  *     POSIX fileio.c
1.1       deraadt     7:  */
1.49      db          8: #include "def.h"
1.1       deraadt     9:
1.56      deraadt    10:
                     11: #include <sys/types.h>
1.53      kjell      12: #ifndef NO_DIRED
1.56      deraadt    13: #include <sys/time.h>
                     14: #include <sys/resource.h>
1.53      kjell      15: #include <sys/wait.h>
                     16: #include "kbd.h"
                     17: #endif /* !NO_DIRED */
1.33      vincent    18: #include <limits.h>
1.1       deraadt    19: #include <sys/stat.h>
                     20: #include <sys/dir.h>
1.21      vincent    21: #include <string.h>
1.9       millert    22: #include <fcntl.h>
                     23: #include <unistd.h>
1.1       deraadt    24:
1.49      db         25: static FILE    *ffp;
                     26:
1.1       deraadt    27: /*
                     28:  * Open a file for reading.
                     29:  */
1.7       millert    30: int
1.25      vincent    31: ffropen(const char *fn, BUFFER *bp)
1.7       millert    32: {
1.16      mickey     33:        struct stat     statbuf;
1.7       millert    34:
1.46      jfb        35:        if ((ffp = fopen(fn, "r")) == NULL) {
                     36:                if (errno == ENOENT)
                     37:                        return (FIOFNF);
                     38:                return (FIOERR);
                     39:        }
1.53      kjell      40:
                     41:        /* If 'fn' is a directory open it with dired. */
1.54      kjell      42:        if (fisdir(fn) == TRUE)
1.53      kjell      43: #ifdef NO_DIRED
                     44:                return (FIOERR);
                     45: #else
                     46:                return (FIODIR);
                     47: #endif /* NO_DIRED */
                     48:
1.1       deraadt    49:        if (bp && fstat(fileno(ffp), &statbuf) == 0) {
1.7       millert    50:                /* set highorder bit to make sure this isn't all zero */
1.1       deraadt    51:                bp->b_fi.fi_mode = statbuf.st_mode | 0x8000;
                     52:                bp->b_fi.fi_uid = statbuf.st_uid;
                     53:                bp->b_fi.fi_gid = statbuf.st_gid;
                     54:        }
1.53      kjell      55:
1.1       deraadt    56:        return (FIOSUC);
                     57: }
                     58:
                     59: /*
                     60:  * Open a file for writing.
                     61:  */
1.7       millert    62: int
1.25      vincent    63: ffwopen(const char *fn, BUFFER *bp)
1.7       millert    64: {
1.49      db         65:        int     fd;
                     66:        mode_t  mode = DEFFILEMODE;
1.7       millert    67:
1.24      deraadt    68:        if (bp && bp->b_fi.fi_mode)
                     69:                mode = bp->b_fi.fi_mode & 07777;
                     70:
                     71:        fd = open(fn, O_RDWR | O_CREAT | O_TRUNC, mode);
                     72:        if (fd == -1) {
                     73:                ffp = NULL;
1.21      vincent    74:                ewprintf("Cannot open file for writing : %s", strerror(errno));
1.1       deraadt    75:                return (FIOERR);
1.34      deraadt    76:        }
1.24      deraadt    77:
                     78:        if ((ffp = fdopen(fd, "w")) == NULL) {
                     79:                ewprintf("Cannot open file for writing : %s", strerror(errno));
                     80:                close(fd);
1.34      deraadt    81:                return (FIOERR);
1.1       deraadt    82:        }
1.7       millert    83:
                     84:        /*
                     85:         * If we have file information, use it.  We don't bother to check for
                     86:         * errors, because there's no a lot we can do about it.  Certainly
1.24      deraadt    87:         * trying to change ownership will fail if we aren't root.  That's
1.7       millert    88:         * probably OK.  If we don't have info, no need to get it, since any
                     89:         * future writes will do the same thing.
1.1       deraadt    90:         */
                     91:        if (bp && bp->b_fi.fi_mode) {
1.28      deraadt    92:                fchmod(fd, bp->b_fi.fi_mode & 07777);
                     93:                fchown(fd, bp->b_fi.fi_uid, bp->b_fi.fi_gid);
1.1       deraadt    94:        }
                     95:        return (FIOSUC);
                     96: }
                     97:
                     98: /*
                     99:  * Close a file.
1.7       millert   100:  * XXX - Should look at the status.
1.1       deraadt   101:  */
1.7       millert   102: /* ARGSUSED */
                    103: int
1.25      vincent   104: ffclose(BUFFER *bp)
1.7       millert   105: {
1.13      art       106:        (void) fclose(ffp);
1.1       deraadt   107:        return (FIOSUC);
                    108: }
                    109:
                    110: /*
1.41      vincent   111:  * Write a buffer to the already opened file. bp points to the
1.1       deraadt   112:  * buffer. Return the status.
                    113:  */
1.7       millert   114: int
1.25      vincent   115: ffputbuf(BUFFER *bp)
1.1       deraadt   116: {
1.41      vincent   117:        LINE   *lp, *lpend;
1.7       millert   118:
                    119:        lpend = bp->b_linep;
1.41      vincent   120:        for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) {
                    121:                if (fwrite(ltext(lp), 1, llength(lp), ffp) != llength(lp)) {
                    122:                        ewprintf("Write I/O error");
1.49      db        123:                        return (FIOERR);
1.7       millert   124:                }
1.41      vincent   125:                if (lforw(lp) != lpend)         /* no implied \n on last line */
                    126:                        putc('\n', ffp);
1.48      deraadt   127:        }
1.42      vincent   128:        /*
                    129:         * XXX should be variable controlled (once we have variables)
                    130:         */
                    131:        if (llength(lback(lpend)) != 0) {
                    132:                if (eyorn("No newline at end of file, add one") == TRUE) {
                    133:                        lnewline_at(lback(lpend), llength(lback(lpend)));
                    134:                        putc('\n', ffp);
                    135:                }
                    136:        }
1.7       millert   137:        return (FIOSUC);
1.1       deraadt   138: }
                    139:
                    140: /*
                    141:  * Read a line from a file, and store the bytes
                    142:  * in the supplied buffer. Stop on end of file or end of
                    143:  * line.  When FIOEOF is returned, there is a valid line
                    144:  * of data without the normally implied \n.
                    145:  */
1.7       millert   146: int
1.25      vincent   147: ffgetline(char *buf, int nbuf, int *nbytes)
1.1       deraadt   148: {
1.16      mickey    149:        int     c, i;
1.1       deraadt   150:
                    151:        i = 0;
1.7       millert   152:        while ((c = getc(ffp)) != EOF && c != '\n') {
1.1       deraadt   153:                buf[i++] = c;
1.7       millert   154:                if (i >= nbuf)
1.49      db        155:                        return (FIOLONG);
1.1       deraadt   156:        }
1.7       millert   157:        if (c == EOF && ferror(ffp) != FALSE) {
1.1       deraadt   158:                ewprintf("File read error");
1.49      db        159:                return (FIOERR);
1.1       deraadt   160:        }
                    161:        *nbytes = i;
1.49      db        162:        return (c == EOF ? FIOEOF : FIOSUC);
1.1       deraadt   163: }
                    164:
                    165: #ifndef NO_BACKUP
                    166: /*
1.9       millert   167:  * Make a backup copy of "fname".  On Unix the backup has the same
                    168:  * name as the original file, with a "~" on the end; this seems to
                    169:  * be newest of the new-speak. The error handling is all in "file.c".
                    170:  * We do a copy instead of a rename since otherwise another process
                    171:  * with an open fd will get the backup, not the new file.  This is
                    172:  * a problem when using mg with things like crontab and vipw.
1.1       deraadt   173:  */
1.7       millert   174: int
1.25      vincent   175: fbackupfile(const char *fn)
1.7       millert   176: {
1.49      db        177:        struct stat      sb;
                    178:        int              from, to, serrno;
                    179:        ssize_t          nread;
                    180:        char             buf[BUFSIZ];
1.44      millert   181:        char            *nname, *tname;
1.1       deraadt   182:
1.35      vincent   183:        if (stat(fn, &sb) == -1) {
                    184:                ewprintf("Can't stat %s : %s", fn, strerror(errno));
                    185:                return (FALSE);
                    186:        }
                    187:
1.21      vincent   188:        if (asprintf(&nname, "%s~", fn) == -1) {
1.44      millert   189:                ewprintf("Can't allocate temp file name : %s", strerror(errno));
                    190:                return (ABORT);
                    191:        }
                    192:
                    193:        if (asprintf(&tname, "%s.XXXXXXXXXX", fn) == -1) {
                    194:                ewprintf("Can't allocate temp file name : %s", strerror(errno));
                    195:                free(nname);
1.1       deraadt   196:                return (ABORT);
1.9       millert   197:        }
                    198:
1.21      vincent   199:        if ((from = open(fn, O_RDONLY)) == -1) {
                    200:                free(nname);
1.44      millert   201:                free(tname);
1.1       deraadt   202:                return (FALSE);
1.21      vincent   203:        }
1.44      millert   204:        to = mkstemp(tname);
1.9       millert   205:        if (to == -1) {
                    206:                serrno = errno;
                    207:                close(from);
1.21      vincent   208:                free(nname);
1.44      millert   209:                free(tname);
1.9       millert   210:                errno = serrno;
                    211:                return (FALSE);
                    212:        }
                    213:        while ((nread = read(from, buf, sizeof(buf))) > 0) {
                    214:                if (write(to, buf, nread) != nread) {
1.40      vincent   215:                        nread = -1;
                    216:                        break;
1.9       millert   217:                }
1.1       deraadt   218:        }
1.9       millert   219:        serrno = errno;
1.44      millert   220:        (void) fchmod(to, (sb.st_mode & 0777));
1.9       millert   221:        close(from);
                    222:        close(to);
1.21      vincent   223:        if (nread == -1) {
1.44      millert   224:                if (unlink(tname) == -1)
1.21      vincent   225:                        ewprintf("Can't unlink temp : %s", strerror(errno));
1.44      millert   226:        } else {
                    227:                if (rename(tname, nname) == -1) {
                    228:                        ewprintf("Can't rename temp : %s", strerror(errno));
                    229:                        (void) unlink(tname);
1.45      henning   230:                        nread = -1;
1.44      millert   231:                }
1.21      vincent   232:        }
1.1       deraadt   233:        free(nname);
1.44      millert   234:        free(tname);
1.9       millert   235:        errno = serrno;
1.22      deraadt   236:
1.9       millert   237:        return (nread == -1 ? FALSE : TRUE);
1.1       deraadt   238: }
                    239: #endif
                    240:
                    241: /*
                    242:  * The string "fn" is a file name.
                    243:  * Perform any required appending of directory name or case adjustments.
1.39      jmc       244:  * If NO_DIR is not defined, the same file should be referred to even if the
1.1       deraadt   245:  * working directory changes.
                    246:  */
                    247: #ifdef SYMBLINK
                    248: #include <sys/types.h>
                    249: #include <sys/stat.h>
                    250: #ifndef MAXLINK
                    251: #define MAXLINK 8              /* maximum symbolic links to follow */
                    252: #endif
                    253: #endif
                    254: #include <pwd.h>
                    255: #ifndef NO_DIR
1.16      mickey    256: extern char    *wdir;
1.1       deraadt   257: #endif
                    258:
1.7       millert   259: char *
1.25      vincent   260: adjustname(const char *fn)
1.1       deraadt   261: {
1.49      db        262:        static char      fnb[MAXPATHLEN];
1.58    ! kjell     263:        const char      *cp, *ep = NULL;
1.57      kjell     264:        char             user[LOGIN_NAME_MAX], path[MAXPATHLEN];
                    265:        size_t           ulen, plen;
1.33      vincent   266:
                    267:        path[0] = '\0';
1.58    ! kjell     268:
        !           269:        cp = fn + strlen(fn) - 1;
        !           270:        for (; cp >= fn; cp--) {
        !           271:                if (ep && (*cp == '/')) {
        !           272:                        fn = ep;
        !           273:                        break;
        !           274:                }
        !           275:                if (*cp == '/' || *cp == '~')
        !           276:                        ep = cp;
        !           277:                else
        !           278:                        ep = NULL;
        !           279:        }
        !           280:
1.33      vincent   281:        /* first handle tilde expansion */
                    282:        if (fn[0] == '~') {
                    283:                struct passwd *pw;
                    284:
                    285:                cp = strchr(fn, '/');
                    286:                if (cp == NULL)
                    287:                        cp = fn + strlen(fn); /* point to the NUL byte */
1.57      kjell     288:                ulen = cp - &fn[1];
                    289:                if (ulen >= sizeof(user)) {
                    290:                        ewprintf("Login name too long");
1.33      vincent   291:                        return (NULL);
                    292:                }
1.57      kjell     293:                if (ulen == 0) /* ~/ or ~ */
                    294:                        (void)strlcpy(user, getlogin(), sizeof(user));
                    295:                else { /* ~user/ or ~user */
                    296:                        memcpy(user, &fn[1], ulen);
                    297:                        user[ulen] = '\0';
                    298:                }
1.33      vincent   299:                pw = getpwnam(user);
                    300:                if (pw == NULL) {
1.57      kjell     301:                        ewprintf("Unknown user %s", user);
1.33      vincent   302:                        return (NULL);
                    303:                }
1.57      kjell     304:                plen = strlcpy(path, pw->pw_dir, sizeof(path));
                    305:                if (plen == 0 || path[plen - 1] != '/') {
                    306:                        if (strlcat(path, "/", sizeof(path)) >= sizeof(path)) {
                    307:                                ewprintf("Path too long");
                    308:                                return (NULL);
                    309:                        }
1.1       deraadt   310:                }
1.33      vincent   311:                fn = cp;
                    312:                if (*fn == '/')
1.7       millert   313:                        fn++;
                    314:        }
1.57      kjell     315:        if (strlcat(path, fn, sizeof(path)) >= sizeof(path)) {
                    316:                ewprintf("Path too long");
                    317:                return (NULL);
                    318:        }
1.33      vincent   319:
1.47      henning   320:        if (realpath(path, fnb) == NULL)
1.57      kjell     321:                (void)strlcpy(fnb, path, sizeof(fnb));
1.47      henning   322:
                    323:        return (fnb);
1.1       deraadt   324: }
                    325:
                    326: #ifndef NO_STARTUP
                    327: /*
                    328:  * Find a startup file for the user and return its name. As a service
                    329:  * to other pieces of code that may want to find a startup file (like
                    330:  * the terminal driver in particular), accepts a suffix to be appended
                    331:  * to the startup file name.
                    332:  */
                    333: char *
1.27      millert   334: startupfile(char *suffix)
1.1       deraadt   335: {
1.49      db        336:        static char      file[NFILEN];
1.16      mickey    337:        char            *home;
1.12      art       338:
                    339:        if ((home = getenv("HOME")) == NULL || *home == '\0')
                    340:                goto nohome;
1.1       deraadt   341:
1.12      art       342:        if (suffix == NULL) {
                    343:                if (snprintf(file, sizeof(file), "%s/.mg", home)
1.32      vincent   344:                    >= sizeof(file))
                    345:                        return (NULL);
1.12      art       346:        } else {
                    347:                if (snprintf(file, sizeof(file), "%s/.mg-%s", home, suffix)
1.32      vincent   348:                    >= sizeof(file))
                    349:                        return (NULL);
1.1       deraadt   350:        }
1.12      art       351:
                    352:        if (access(file, R_OK) == 0)
1.32      vincent   353:                return (file);
1.12      art       354: nohome:
                    355: #ifdef STARTUPFILE
1.27      millert   356:        if (suffix == NULL) {
1.12      art       357:                if (snprintf(file, sizeof(file), "%s", STARTUPFILE)
1.32      vincent   358:                    >= sizeof(file))
                    359:                        return (NULL);
1.12      art       360:        } else {
                    361:                if (snprintf(file, sizeof(file), "%s%s", STARTUPFILE, suffix)
1.32      vincent   362:                    >= sizeof(file))
                    363:                        return (NULL);
1.12      art       364:        }
                    365:
                    366:        if (access(file, R_OK) == 0)
1.32      vincent   367:                return (file);
1.1       deraadt   368: #endif
1.32      vincent   369:        return (NULL);
1.1       deraadt   370: }
                    371: #endif
                    372:
                    373: #ifndef NO_DIRED
                    374:
1.7       millert   375: int
1.27      millert   376: copy(char *frname, char *toname)
1.1       deraadt   377: {
1.49      db        378:        int     ifd, ofd, n;
                    379:        char    buf[BUFSIZ];
                    380:        mode_t  mode = DEFFILEMODE;     /* XXX?? */
                    381:        struct  stat orig;
1.30      vincent   382:
                    383:        if ((ifd = open(frname, O_RDONLY)) == -1)
                    384:                return (FALSE);
                    385:        if (fstat(ifd, &orig) == -1) {
                    386:                ewprintf("fstat: %s", strerror(errno));
                    387:                close(ifd);
                    388:                return (FALSE);
                    389:        }
                    390:
                    391:        if ((ofd = open(toname, O_WRONLY|O_CREAT|O_TRUNC, mode)) == -1) {
                    392:                close(ifd);
                    393:                return (FALSE);
                    394:        }
1.49      db        395:        while ((n = read(ifd, buf, sizeof(buf))) > 0) {
1.30      vincent   396:                if (write(ofd, buf, n) != n) {
                    397:                        ewprintf("write error : %s", strerror(errno));
                    398:                        break;
                    399:                }
                    400:        }
                    401:        if (fchmod(ofd, orig.st_mode) == -1)
                    402:                ewprintf("Cannot set original mode : %s", strerror(errno));
1.1       deraadt   403:
1.30      vincent   404:        if (n == -1) {
                    405:                ewprintf("Read error : %s", strerror(errno));
                    406:                close(ifd);
                    407:                close(ofd);
                    408:                return (FALSE);
1.7       millert   409:        }
1.30      vincent   410:        /*
1.32      vincent   411:         * It is "normal" for this to fail since we can't guarantee that
1.49      db        412:         * we will be running as root.
1.30      vincent   413:         */
                    414:        if (fchown(ofd, orig.st_uid, orig.st_gid) && errno != EPERM)
                    415:                ewprintf("Cannot set owner : %s", strerror(errno));
                    416:
                    417:        (void) close(ifd);
                    418:        (void) close(ofd);
                    419:
                    420:        return (TRUE);
1.7       millert   421: }
                    422:
                    423: #endif                         /* NO_DIRED */
1.1       deraadt   424:
                    425: struct filelist {
1.16      mickey    426:        LIST    fl_l;
                    427:        char    fl_name[NFILEN + 2];
1.1       deraadt   428: };
                    429:
1.7       millert   430: /*
1.1       deraadt   431:  * return list of file names that match the name in buf.
                    432:  */
1.7       millert   433: LIST *
1.25      vincent   434: make_file_list(char *buf)
1.7       millert   435: {
1.16      mickey    436:        char            *dir, *file, *cp;
1.49      db        437:        int              len, preflen;
1.16      mickey    438:        DIR             *dirp;
                    439:        struct dirent   *dent;
                    440:        LIST            *last;
1.7       millert   441:        struct filelist *current;
1.49      db        442:        char             prefixx[NFILEN + 1];
1.7       millert   443:
                    444:        /*
                    445:         * We need three different strings: dir - the name of the directory
                    446:         * containing what the user typed. Must be a real unix file name,
                    447:         * e.g. no ~user, etc..  Must not end in /. prefix - the portion of
                    448:         * what the user typed that is before the names we are going to find
                    449:         * in the directory.  Must have a trailing / if the user typed it.
1.49      db        450:         * names from the directory. We open dir, and return prefix
1.7       millert   451:         * concatenated with names.
                    452:         */
                    453:
                    454:        /* first we get a directory name we can look up */
                    455:        /*
                    456:         * Names ending in . are potentially odd, because adjustname will
                    457:         * treat foo/.. as a reference to another directory, whereas we are
                    458:         * interested in names starting with ..
                    459:         */
                    460:        len = strlen(buf);
                    461:        if (buf[len - 1] == '.') {
                    462:                buf[len - 1] = 'x';
                    463:                dir = adjustname(buf);
                    464:                buf[len - 1] = '.';
                    465:        } else
                    466:                dir = adjustname(buf);
1.33      vincent   467:        if (dir == NULL)
1.36      vincent   468:                return (NULL);
1.7       millert   469:        /*
                    470:         * If the user typed a trailing / or the empty string
                    471:         * he wants us to use his file spec as a directory name.
                    472:         */
                    473:        if (buf[0] && buf[strlen(buf) - 1] != '/') {
                    474:                file = strrchr(dir, '/');
                    475:                if (file) {
                    476:                        *file = 0;
                    477:                        if (*dir == 0)
                    478:                                dir = "/";
1.49      db        479:                } else
1.7       millert   480:                        return (NULL);
1.1       deraadt   481:        }
1.7       millert   482:        /* Now we get the prefix of the name the user typed. */
1.49      db        483:        strlcpy(prefixx, buf, sizeof(prefixx));
1.7       millert   484:        cp = strrchr(prefixx, '/');
                    485:        if (cp == NULL)
                    486:                prefixx[0] = 0;
                    487:        else
                    488:                cp[1] = 0;
                    489:
                    490:        preflen = strlen(prefixx);
1.49      db        491:        /* cp is the tail of buf that really needs to be compared. */
1.7       millert   492:        cp = buf + preflen;
                    493:        len = strlen(cp);
                    494:
                    495:        /*
                    496:         * Now make sure that file names will fit in the buffers allocated.
                    497:         * SV files are fairly short.  For BSD, something more general would
                    498:         * be required.
                    499:         */
                    500:        if ((preflen + MAXNAMLEN) > NFILEN)
                    501:                return (NULL);
                    502:
                    503:        /* loop over the specified directory, making up the list of files */
                    504:
                    505:        /*
                    506:         * Note that it is worth our time to filter out names that don't
                    507:         * match, even though our caller is going to do so again, and to
                    508:         * avoid doing the stat if completion is being done, because stat'ing
                    509:         * every file in the directory is relatively expensive.
                    510:         */
1.1       deraadt   511:
1.11      art       512:        dirp = opendir(dir);
                    513:        if (dirp == NULL)
1.7       millert   514:                return (NULL);
                    515:        last = NULL;
1.11      art       516:
                    517:        while ((dent = readdir(dirp)) != NULL) {
1.18      art       518:                int isdir;
                    519:
1.11      art       520:                if (dent->d_namlen < len || memcmp(cp, dent->d_name, len) != 0)
                    521:                        continue;
                    522:
1.18      art       523:                isdir = 0;
                    524:                if (dent->d_type == DT_DIR) {
                    525:                        isdir = 1;
                    526:                } else if (dent->d_type == DT_LNK ||
                    527:                            dent->d_type == DT_UNKNOWN) {
                    528:                        struct stat     statbuf;
                    529:                        char            statname[NFILEN + 2];
                    530:
                    531:                        statbuf.st_mode = 0;
                    532:                        if (snprintf(statname, sizeof(statname), "%s/%s",
                    533:                            dir, dent->d_name) > sizeof(statname) - 1) {
                    534:                                continue;
                    535:                        }
                    536:                        if (stat(statname, &statbuf) < 0)
                    537:                                continue;
                    538:                        if (statbuf.st_mode & S_IFDIR)
                    539:                                isdir = 1;
                    540:                }
                    541:
                    542:                current = malloc(sizeof(struct filelist));
1.12      art       543:                if (current == NULL)
                    544:                        break;
1.18      art       545:
1.11      art       546:                if (snprintf(current->fl_name, sizeof(current->fl_name),
1.18      art       547:                    "%s%s%s", prefixx, dent->d_name, isdir ? "/" : "")
                    548:                    >= sizeof(current->fl_name)) {
1.11      art       549:                        free(current);
1.7       millert   550:                        continue;
                    551:                }
                    552:                current->fl_l.l_next = last;
                    553:                current->fl_l.l_name = current->fl_name;
                    554:                last = (LIST *) current;
1.1       deraadt   555:        }
1.11      art       556:        closedir(dirp);
1.1       deraadt   557:
1.7       millert   558:        return (last);
1.54      kjell     559: }
                    560:
                    561: /*
                    562:  * Test if a supplied filename refers to a directory
                    563:  * Returns ABORT on error, TRUE if directory. FALSE otherwise
                    564:  */
                    565: int
                    566: fisdir(const char *fname)
                    567: {
                    568:        struct stat     statbuf;
                    569:
                    570:        if (stat(fname, &statbuf) != 0)
                    571:                return (ABORT);
                    572:
                    573:        if (S_ISDIR(statbuf.st_mode))
                    574:                return (TRUE);
                    575:
                    576:        return (FALSE);
1.1       deraadt   577: }