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

Annotation of src/usr.bin/mg/dir.c, Revision 1.16

1.16    ! kjell       1: /*     $OpenBSD: dir.c,v 1.15 2005/11/20 18:47:11 kjell Exp $  */
1.13      kjell       2:
                      3: /* This file is in the public domain. */
1.4       niklas      4:
1.1       deraadt     5: /*
                      6:  * Name:       MG 2a
                      7:  *             Directory management functions
                      8:  * Created:    Ron Flax (ron@vsedev.vse.com)
                      9:  *             Modified for MG 2a by Mic Kaczmarczik 03-Aug-1987
                     10:  */
                     11:
                     12: #include "def.h"
                     13:
1.6       mickey     14: char           *wdir;
1.12      db         15: static char     cwd[NFILEN];
1.1       deraadt    16:
                     17: /*
1.12      db         18:  * Initialize anything the directory management routines need.
1.1       deraadt    19:  */
1.5       art        20: void
1.8       vincent    21: dirinit(void)
1.1       deraadt    22: {
1.10      vincent    23:        if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL) {
                     24:                ewprintf("Can't get current directory!");
                     25:                chdir("/");
1.16    ! kjell      26:                (void)strlcpy(cwd, "/", sizeof(cwd));
1.10      vincent    27:        }
1.1       deraadt    28: }
                     29:
                     30: /*
1.12      db         31:  * Change current working directory.
1.1       deraadt    32:  */
1.3       millert    33: /* ARGSUSED */
                     34: int
1.8       vincent    35: changedir(int f, int n)
1.1       deraadt    36: {
1.11      vincent    37:        char    bufc[NPAT], *bufp;
1.1       deraadt    38:
1.14      kjell      39:        (void)strlcpy(bufc, wdir, sizeof(bufc));
                     40:        if ((bufp = eread("Change default directory: ", bufc, NPAT,
                     41:            EFDEF | EFNEW | EFCR)) == NULL)
1.12      db         42:                return (ABORT);
1.14      kjell      43:        else if (bufp[0] == '\0')
                     44:                return (FALSE);
1.1       deraadt    45:        if (chdir(bufc) == -1) {
                     46:                ewprintf("Can't change dir to %s", bufc);
1.3       millert    47:                return (FALSE);
1.1       deraadt    48:        } else {
1.9       vincent    49:                if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL)
1.1       deraadt    50:                        panic("Can't get current directory!");
                     51:                ewprintf("Current directory is now %s", wdir);
1.3       millert    52:                return (TRUE);
1.1       deraadt    53:        }
                     54: }
                     55:
                     56: /*
1.12      db         57:  * Show current directory.
1.1       deraadt    58:  */
1.3       millert    59: /* ARGSUSED */
                     60: int
1.8       vincent    61: showcwdir(int f, int n)
1.1       deraadt    62: {
                     63:        ewprintf("Current directory: %s", wdir);
1.3       millert    64:        return (TRUE);
1.1       deraadt    65: }