From 494210424c9d6e7789052db390186939682c11ef Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 30 May 2014 15:27:56 +0800 Subject: [PATCH] Introduce fname_t type and remove need of NFILEN filename length constant. --- buffer.h | 5 +++-- file.c | 24 ++++++++++++------------ file.h | 2 -- main.c | 4 ++-- spawn.c | 2 +- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/buffer.h b/buffer.h index 2b69eb8..3109de8 100644 --- a/buffer.h +++ b/buffer.h @@ -4,10 +4,11 @@ #include "crypt.h" #include "line.h" -#define NFILEN 80 /* # of bytes, file name */ #define NBUFN 16 /* # of bytes, buffer name */ #define NPAT 128 /* # of bytes, pattern */ +typedef char fname_t[ 80] ; + /* * Text is kept in buffers. A buffer header, described below, exists for every * buffer in the system. The buffers are kept in a big list, so that commands @@ -30,7 +31,7 @@ struct buffer { char b_active; /* window activated flag */ char b_nwnd; /* Count of windows on buffer */ char b_flag; /* Flags */ - char b_fname[NFILEN]; /* File name */ + fname_t b_fname ; /* File name */ char b_bname[NBUFN]; /* Buffer name */ #if CRYPT char b_key[NPAT]; /* current encrypted key */ diff --git a/file.c b/file.c index bd69bdd..1caa65c 100644 --- a/file.c +++ b/file.c @@ -60,11 +60,11 @@ boolean restflag = FALSE ; /* restricted use? */ int fileread(int f, int n) { int s; - char fname[NFILEN]; + fname_t fname ; if (restflag) /* don't allow this command if restricted */ return resterr(); - if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE) + if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE) return s; return readin(fname, TRUE); } @@ -79,13 +79,13 @@ int fileread(int f, int n) int insfile(int f, int n) { int s; - char fname[NFILEN]; + fname_t fname ; if (restflag) /* don't allow this command if restricted */ return resterr(); if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ - if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE) + if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE) return s; if ((s = ifile(fname)) != TRUE) return s; @@ -103,25 +103,25 @@ int insfile(int f, int n) */ int filefind(int f, int n) { - char fname[NFILEN]; /* file user wishes to find */ + fname_t fname ; /* file user wishes to find */ int s; /* status return */ if (restflag) /* don't allow this command if restricted */ return resterr(); - if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE) + if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE) return s; return getfile(fname, TRUE); } int viewfile(int f, int n) { /* visit a file in VIEW mode */ - char fname[NFILEN]; /* file user wishes to find */ + fname_t fname ; /* file user wishes to find */ int s; /* status return */ struct window *wp; /* scan for windows that need updating */ if (restflag) /* don't allow this command if restricted */ return resterr(); - if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE) + if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE) return s; s = getfile(fname, FALSE); if (s) { /* if we succeed, put it in view mode */ @@ -481,11 +481,11 @@ int filewrite(int f, int n) { struct window *wp; int s; - char fname[NFILEN]; + fname_t fname ; if (restflag) /* don't allow this command if restricted */ return resterr(); - if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE) + if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE) return s; if ((s = writeout(fname)) == TRUE) { strcpy(curbp->b_fname, fname); @@ -608,11 +608,11 @@ int filename(int f, int n) { struct window *wp; int s; - char fname[NFILEN]; + fname_t fname ; if (restflag) /* don't allow this command if restricted */ return resterr(); - if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT) + if ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT) return s; if (s == FALSE) strcpy(curbp->b_fname, ""); diff --git a/file.h b/file.h index 0d0330b..ab3ca71 100644 --- a/file.h +++ b/file.h @@ -11,8 +11,6 @@ void cryptbufferkey( struct buffer *bp) ; int set_encryption_key( int f, int n) ; #endif -#define NFILEN 80 /* # of bytes, file name */ - extern boolean restflag ; /* restricted use? */ int fileread( int f, int n) ; diff --git a/main.c b/main.c index 812ce14..8c864c3 100644 --- a/main.c +++ b/main.c @@ -274,8 +274,8 @@ int main(int argc, char **argv) /* set this to inactive */ bp = bfind(bname, TRUE, 0); - strncpy( bp->b_fname, argv[ carg], NFILEN - 1) ; /* max filename length limited to NFILEN - 1 (79) */ - bp->b_fname[ NFILEN - 1] = 0 ; + strncpy( bp->b_fname, argv[ carg], sizeof bp->b_fname - 1) ; /* max filename length limited to NFILEN - 1 (79) */ + bp->b_fname[ sizeof bp->b_fname - 1] = 0 ; bp->b_active = FALSE; if (firstfile) { firstbp = bp; diff --git a/spawn.c b/spawn.c index 2a55bff..0c50ab9 100644 --- a/spawn.c +++ b/spawn.c @@ -401,7 +401,7 @@ int filter_buffer(int f, int n) int s; /* return status from CLI */ struct buffer *bp; /* pointer to buffer to zot */ char line[NLINE]; /* command line send to shell */ - char tmpnam[NFILEN]; /* place to store real file name */ + fname_t tmpnam ; /* place to store real file name */ static char bname1[] = "fltinp"; static char filnam1[] = "fltinp";