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

1.10    ! vincent     1: /*     $OpenBSD: dir.c,v 1.9 2002/07/01 14:33:44 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.10    ! vincent    22:        if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL) {
        !            23:                ewprintf("Can't get current directory!");
        !            24:                chdir("/");
        !            25:                strlcpy(cwd, "/", sizeof(cwd));
        !            26:        }
1.1       deraadt    27: }
                     28:
                     29: /*
                     30:  * Change current working directory
                     31:  */
1.3       millert    32: /* ARGSUSED */
                     33: int
1.8       vincent    34: changedir(int f, int n)
1.1       deraadt    35: {
1.6       mickey     36:        int     s;
                     37:        char    bufc[NPAT];
1.1       deraadt    38:
1.3       millert    39:        if ((s = ereply("Change default directory: ", bufc, NPAT)) != TRUE)
                     40:                return (s);
1.1       deraadt    41:        if (bufc[0] == '\0')
1.9       vincent    42:                (void)strlcpy(bufc, wdir, sizeof bufc);
1.1       deraadt    43:        if (chdir(bufc) == -1) {
                     44:                ewprintf("Can't change dir to %s", bufc);
1.3       millert    45:                return (FALSE);
1.1       deraadt    46:        } else {
1.9       vincent    47:                if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL)
1.1       deraadt    48:                        panic("Can't get current directory!");
                     49:                ewprintf("Current directory is now %s", wdir);
1.3       millert    50:                return (TRUE);
1.1       deraadt    51:        }
                     52: }
                     53:
                     54: /*
                     55:  * Show current directory
                     56:  */
1.3       millert    57: /* ARGSUSED */
                     58: int
1.8       vincent    59: showcwdir(int f, int n)
1.1       deraadt    60: {
1.3       millert    61:
1.1       deraadt    62:        ewprintf("Current directory: %s", wdir);
1.3       millert    63:        return (TRUE);
1.1       deraadt    64: }
                     65: #endif