[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.8

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