-/* Citadel/UX support routines */
+/*
+ * $Id$
+ *
+ * Client-side support functions.
+ *
+ */
#include "sysdep.h"
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif
+#include "citadel.h"
+#include "citadel_ipc.h"
+#include "screen.h"
+
+#ifndef HAVE_GETUTLINE
+struct utmp *getutline(struct utmp *ut);
+#endif
#define ROUTINES_C
#include "citadel.h"
#include "routines.h"
-
-char inkey(void);
-void sttybbs(int cmd);
-void newprompt(char *prompt, char *str, int len);
-void val_user(char *user);
-int intprompt(char *prompt, int ival, int imin, int imax);
-void formout(char *name);
-void logoff(int code);
-void set_keepalives(int s);
-void strprompt(char *prompt, char *str, int len);
-void newprompt(char *prompt, char *str, int len);
-void color(int colornum);
+#include "commands.h"
+#include "tools.h"
+#include "citadel_decls.h"
+#include "routines2.h"
#define IFAIDE if(axlevel>=6)
#define IFNAIDE if (axlevel<6)
extern unsigned userflags;
extern char *axdefs[7];
extern char sigcaught;
-extern struct CtdlServInfo serv_info;
extern char rc_floor_mode;
+extern int rc_ansi_color;
+extern int rc_prompt_control;
-int struncmp(char *lstr, char *rstr, int len)
-{
- int pos = 0;
- char lc,rc;
- while (pos<len) {
- lc=tolower(lstr[pos]);
- rc=tolower(rstr[pos]);
- if ((lc==0)&&(rc==0)) return(0);
- if (lc<rc) return(-1);
- if (lc>rc) return(1);
- pos=pos+1;
- }
- return(0);
+/* Destructive backspace */
+void back(int spaces) {
+ int a;
+ for (a=0; a<spaces; ++a) {
+ scr_putc(8);
+ scr_putc(32);
+ scr_putc(8);
}
+}
-
-/*
- * check for the presence of a character within a string (returns count)
- */
-int haschar(char *st, int ch)
-{
+void hit_any_key(CtdlIPC *ipc) { /* hit any key to continue */
int a,b;
- b=0;
- for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
- return(b);
- }
-
-/*
- * num_parms() - discover number of parameters...
- */
-int num_parms(char *source)
-{
- int a;
- int count = 1;
-
- for (a=0; a<strlen(source); ++a)
- if (source[a]=='|') ++count;
- return(count);
+ color(COLOR_PUSH);
+ color(DIM_RED);
+ scr_printf("%s\r", ipc->ServInfo.moreprompt);
+ color(COLOR_POP);
+ stty_ctdl(0);
+ b=inkey();
+ for (a=0; !IsEmptyStr(&ipc->ServInfo.moreprompt[0]); ++a)
+ scr_putc(' ');
+ scr_putc(13);
+ stty_ctdl(1);
+ if ( (rc_prompt_control == 1)
+ || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
+ if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
+ b = STOP_KEY;
+ if (b == 'n' || b == 'N')
+ b = NEXT_KEY;
}
+ if (b==NEXT_KEY) sigcaught = SIGINT;
+ if (b==STOP_KEY) sigcaught = SIGQUIT;
+}
/*
- * extract() - extract a parameter from a series of "|" separated...
+ * Edit or delete a user (cmd=25 to edit/create, 96 to delete)
*/
-void extract(char *dest, char *source, int parmnum)
+void edituser(CtdlIPC *ipc, int cmd)
{
- char buf[256];
- int count = 0;
- int n;
-
- n = num_parms(source);
-
- if (parmnum >= n) {
- strcpy(dest,"");
- return;
+ char buf[SIZ];
+ char who[USERNAME_SIZE];
+ struct ctdluser *user = NULL;
+ int newnow = 0;
+ int r; /* IPC response code */
+
+ newprompt("User name: ", who, 29);
+ while ((r = CtdlIPCAideGetUserParameters(ipc, who, &user, buf)) / 100 != 2) {
+ scr_printf("%s\n", buf);
+ if (cmd == 25) {
+ scr_printf("Do you want to create this user? ");
+ if (yesno()) {
+ r = CtdlIPCCreateUser(ipc, who, 0, buf);
+ if (r / 100 == 2) {
+ newnow = 1;
+ continue;
+ }
+ scr_printf("%s\n",&buf[4]);
+ }
}
- strcpy(buf,source);
- if ( (parmnum == 0) && (n == 1) ) {
- strcpy(dest,buf);
+ free(user);
return;
- }
-
- while (count++ < parmnum) do {
- strcpy(buf,&buf[1]);
- } while( (strlen(buf)>0) && (buf[0]!='|') );
- if (buf[0]=='|') strcpy(buf,&buf[1]);
- for (count = 0; count<strlen(buf); ++count)
- if (buf[count] == '|') buf[count] = 0;
- strcpy(dest,buf);
- }
-
-/*
- * extract_int() - extract an int parm w/o supplying a buffer
- */
-int extract_int(char *source, int parmnum)
-{
- char buf[256];
-
- extract(buf,source,parmnum);
- return(atoi(buf));
}
-/*
- * extract_long() - extract a long parm w/o supplying a buffer
- */
-long extract_long(char *source, int parmnum)
-{
- char buf[256];
-
- extract(buf,source,parmnum);
- return(atol(buf));
- }
-
-void back(int spaces) /* Destructive backspace */
- {
-int a;
- for (a=1; a<=spaces; ++a) {
- putc(8,stdout); putc(32,stdout); putc(8,stdout);
- }
- }
-
-int yesno(void) { /* Returns 1 for yes, 0 for no */
-int a;
- while (1) {
- a=inkey(); a=tolower(a);
- if (a=='y') { printf("Yes\n"); return(1); }
- if (a=='n') { printf("No\n"); return(0); }
- }
- }
+ if (cmd == 25) {
+ val_user(ipc, user->fullname, 0); /* Display registration */
-int yesno_d(int d) /* Returns 1 for yes, 0 for no, arg is default value */
- {
-int a;
- while (1) {
- a=inkey(); a=tolower(a);
- if (a==13) a=(d ? 'y' : 'n');
- if (a=='y') { printf("Yes\n"); return(1); }
- if (a=='n') { printf("No\n"); return(0); }
+ if (newnow || boolprompt("Change password", 0)) {
+ strprompt("Password", user->password, -19);
}
+
+ user->axlevel = intprompt("Access level", user->axlevel, 0, 6);
+/* user->flags = set_attr(ipc, user->flags,
+ "Permission to send Internet mail",
+ US_INTERNET, 0); */
+ if (boolprompt("Permission to send Internet mail", (user->flags & US_INTERNET)))
+ user->flags |= US_INTERNET;
+ else
+ user->flags &= ~US_INTERNET;
+ if (boolprompt("Ask user to register again", !(user->flags & US_REGIS)))
+ user->flags &= ~US_REGIS;
+ else
+ user->flags |= US_REGIS;
+ user->timescalled = intprompt("Times called",
+ user->timescalled, 0, INT_MAX);
+ user->posted = intprompt("Messages posted",
+ user->posted, 0, INT_MAX);
+ user->lastcall = boolprompt("Set last call to now", 0) ?
+ time(NULL) : user->lastcall;
+ user->USuserpurge = intprompt("Purge time (in days, 0 for system default",
+ user->USuserpurge, 0, INT_MAX);
}
-
-void hit_any_key(void) { /* hit any key to continue */
- int a,b;
-
- printf("%s\r",serv_info.serv_moreprompt);
- sttybbs(0);
- b=inkey();
- for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
- putc(' ',stdout);
- putc(13,stdout);
- sttybbs(1);
- if (b==NEXT_KEY) sigcaught = SIGINT;
- if (b==STOP_KEY) sigcaught = SIGQUIT;
+ if (cmd == 96) {
+ scr_printf("Do you want to delete this user? ");
+ if (!yesno()) return;
+ user->axlevel = 0;
}
-
-/*
- * change a user's access level
- */
-void edituser(void)
-{
- char who[256];
- char buf[256];
-
- newprompt("User name: ",who,25);
- sprintf(buf,"QUSR %s",who);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
- return;
- }
- val_user(who);
+ r = CtdlIPCAideSetUserParameters(ipc, user, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
}
+ free(user);
+}
-int set_attr(int sval, char *prompt, unsigned int sbit)
+/* Display a prompt and flip a bit based on whether the user answers
+ * yes or no. Yes=1 and No=0, unless 'backwards' is set to a nonzero value
+ * in which case No=1 and Yes=0.
+ */
+int set_attr(CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, int backwards)
{
int a;
int temp;
temp = sval;
- color(3);
- printf("%45s [", prompt);
- color(1);
- printf("%3s", ((temp&sbit) ? "Yes":"No"));
- color(3);
- printf("]? ");
- color(2);
- a=yesno_d(temp&sbit);
- color(7);
- temp=(temp|sbit);
- if (!a) temp=(temp^sbit);
- return(temp);
+ color(DIM_WHITE);
+ scr_printf("%50s ", prompt);
+ color(DIM_MAGENTA);
+ scr_printf("[");
+ color(BRIGHT_MAGENTA);
+
+ if (backwards) {
+ scr_printf("%3s", ((temp&sbit) ? "No":"Yes"));
+ }
+ else {
+ scr_printf("%3s", ((temp&sbit) ? "Yes":"No"));
}
+ color(DIM_MAGENTA);
+ scr_printf("]? ");
+ color(BRIGHT_CYAN);
+ a = (temp & sbit);
+ if (a != 0) a = 1;
+ if (backwards) a = 1 - a;
+ a = yesno_d(a);
+ if (backwards) a = 1 - a;
+ color(DIM_WHITE);
+ temp = (temp|sbit);
+ if (!a) temp = (temp^sbit);
+ return(temp);
+}
+
/*
* modes are: 0 - .EC command, 1 - .EC for new user,
* 2 - toggle Xpert mode 3 - toggle floor mode
*/
-void enter_config(int mode)
+void enter_config(CtdlIPC *ipc, int mode)
{
- int width,height,flags;
- char buf[128];
-
- sprintf(buf,"GETU");
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
+ char buf[SIZ];
+ struct ctdluser *user = NULL;
+ int r; /* IPC response code */
+
+ r = CtdlIPCGetConfig(ipc, &user, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ free(user);
return;
- }
-
- width = extract_int(&buf[4],0);
- height = extract_int(&buf[4],1);
- flags = extract_int(&buf[4],2);
-
- if ((mode==0)||(mode==1)) {
+ }
- width = intprompt("Enter your screen width",width,20,255);
- height = intprompt("Enter your screen height",height,3,255);
+ if (mode == 0 || mode == 1) {
+
+ /* Does anyone still use dialup connections with manual
+ * screen dimensions setting anymore? For now we'll keep
+ * the system's ability to set these, but remove the prompts
+ * because they're spurious for nearly everyone.
+ *
+ user->USscreenwidth = intprompt("Enter your screen width",
+ user->USscreenwidth, 20, 255);
+ user->USscreenheight = intprompt("Enter your screen height",
+ user->USscreenheight, 3, 255);
+ */
- flags = set_attr(flags,
- "Are you an experienced Citadel user",US_EXPERT);
- if ( ((flags&US_EXPERT)==0) && (mode==1))
- return;
- flags = set_attr(flags,
- "Print last old message on New message request",US_LASTOLD);
- if ((flags&US_EXPERT)==0) formout("unlisted");
- flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
- flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
- if ((flags & US_NOPROMPT)==0)
- flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
- flags = set_attr(flags,
- "Pause after each screenful of text",US_PAGINATOR);
- if (rc_floor_mode == RC_DEFAULT) {
- flags = set_attr(flags,
- "View rooms by floor",US_FLOORS);
- }
- }
-
- if (mode==2) {
- if (flags & US_EXPERT) {
- flags = (flags ^ US_EXPERT);
- printf("Expert mode now OFF\n");
+ user->flags = set_attr(ipc, user->flags,
+ "Are you an experienced Citadel user",
+ US_EXPERT, 0);
+ if ((user->flags & US_EXPERT) == 0 && mode == 1) {
+ free(user);
+ return;
}
- else {
- flags = (flags | US_EXPERT);
- printf("Expert mode now ON\n");
+
+ user->flags = set_attr(ipc, user->flags,
+ "Print last old message on New message request",
+ US_LASTOLD, 0);
+
+ user->flags = set_attr(ipc, user->flags,
+ "Prompt after each message",
+ US_NOPROMPT, 1);
+
+ if ((user->flags & US_NOPROMPT) == 0)
+ user->flags = set_attr(ipc, user->flags,
+ "Use 'disappearing' prompts",
+ US_DISAPPEAR, 0);
+
+ user->flags = set_attr(ipc, user->flags,
+ "Pause after each screenful of text",
+ US_PAGINATOR, 0);
+
+ if (rc_prompt_control == 3 && (user->flags & US_PAGINATOR))
+ user->flags = set_attr(ipc, user->flags,
+ "<N>ext and <S>top work at paginator prompt",
+ US_PROMPTCTL, 0);
+
+ if (rc_floor_mode == RC_DEFAULT)
+ user->flags = set_attr(ipc, user->flags,
+ "View rooms by floor",
+ US_FLOORS, 0);
+
+ if (rc_ansi_color == 3)
+ user->flags = set_attr(ipc, user->flags,
+ "Enable color support",
+ US_COLOR, 0);
+
+ if ((user->flags & US_EXPERT) == 0)
+ formout(ipc, "unlisted");
+
+ user->flags = set_attr(ipc, user->flags,
+ "Be unlisted in userlog",
+ US_UNLISTED, 0);
+
+ if (!IsEmptyStr(editor_paths[0])) {
+ user->flags = set_attr(ipc, user->flags,
+ "Always enter messages with the full-screen editor",
+ US_EXTEDIT, 0);
}
- }
- if (mode==3) {
- if (flags & US_FLOORS) {
- flags = (flags ^ US_FLOORS);
- printf("Floor mode now OFF\n");
+ }
+
+ if (mode == 2) {
+ if (user->flags & US_EXPERT) {
+ user->flags ^= US_EXPERT;
+ scr_printf("Expert mode now OFF\n");
+ } else {
+ user->flags |= US_EXPERT;
+ scr_printf("Expert mode now ON\n");
}
- else {
- flags = (flags | US_FLOORS);
- printf("Floor mode now ON\n");
+ }
+
+ if (mode == 3) {
+ if (user->flags & US_FLOORS) {
+ user->flags ^= US_FLOORS;
+ scr_printf("Floor mode now OFF\n");
+ } else {
+ user->flags |= US_FLOORS;
+ scr_printf("Floor mode now ON\n");
}
- }
+ }
- sprintf(buf,"SETU %d|%d|%d",width,height,flags);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') printf("%s\n",&buf[4]);
- userflags = flags;
+ r = CtdlIPCSetConfig(ipc, user, buf);
+ if (r / 100 != 2) scr_printf("%s\n", buf);
+ userflags = user->flags;
+ free(user);
}
/*
if (c<0) {
string[a]=0;
return(-1);
- }
+ }
string[a++]=c;
- } while(c!=10);
+ } while(c!=10);
string[a-1]=0;
- } while(string[0]=='#');
+ } while(string[0]=='#');
return(strlen(string));
- }
-
-int pattern(char *search, char *patn) /* Searches for patn in search string */
-
-
-{
- int a,b;
- for (a=0; a<strlen(search); ++a)
- { b=struncmp(&search[a],patn,strlen(patn));
- if (b==0) return(b);
- }
- return(-1);
}
-void interr(int errnum) /* display internal error as defined in errmsgs */
- {
- printf("*** INTERNAL ERROR %d\n",errnum);
- printf("(Press any key to continue)\n");
- inkey();
- logoff(errnum);
-}
-
-
-/*
- * Check to see if we need to pause at the end of a screen.
- * If we do, we have to disable server keepalives during the pause because
- * we are probably in the middle of a server operation and the NOOP command
- * would confuse everything.
- */
-int checkpagin(int lp, int pagin, int height)
-{
- if (pagin!=1) return(0);
- if (lp>=(height-1)) {
- set_keepalives(KA_NO);
- hit_any_key();
- set_keepalives(KA_YES);
- return(0);
- }
- return(lp);
+/* Searches for patn in search string */
+int pattern(char *search, char *patn) {
+ int a,b,len;
+
+ len = strlen(patn);
+ for (a=0; !IsEmptyStr(&search[a]); ++a) {
+ b=strncasecmp(&search[a],patn,len);
+ if (b==0) return(b);
}
+ return(-1);
+}
void strproc(char *string)
{
int a;
- if (strlen(string)==0) return;
+ if (IsEmptyStr(string)) return;
/* Convert non-printable characters to blanks */
- for (a=0; a<strlen(string); ++a) {
+ for (a=0; !IsEmptyStr(&string[a]); ++a) {
if (string[a]<32) string[a]=32;
if (string[a]>126) string[a]=32;
- }
+ }
/* Remove leading and trailing blanks */
while(string[0]<33) strcpy(string,&string[1]);
if ((string[a]==32)&&(string[a+1]==32)) {
strcpy(&string[a],&string[a+1]);
a=0;
- }
}
+ }
/* remove characters which would interfere with the network */
for (a=0; a<strlen(string); ++a) {
if (string[a]==',') strcpy(&string[a],&string[a+1]);
if (string[a]=='%') strcpy(&string[a],&string[a+1]);
if (string[a]=='|') strcpy(&string[a],&string[a+1]);
- }
-
}
+}
+
-#ifdef NO_STRERROR
+#ifndef HAVE_STRERROR
/*
* replacement strerror() for systems that don't have it
*/
char *strerror(int e)
{
- static char buf[32];
+ static char buf[128];
- sprintf(buf,"errno = %d",e);
+ snprintf(buf, sizeof buf, "errno = %d",e);
return(buf);
- }
+}
#endif
-void progress(long int curr, long int cmax)
+void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax)
{
- static long dots_printed;
- long a;
-
- if (curr==0) {
- printf(".......................................");
- printf(".......................................\r");
- fflush(stdout);
- dots_printed = 0;
- }
- else if (curr==cmax) {
- printf("\r%79s\n","");
- }
- else {
- a=(curr * 100) / cmax;
- a=a*78; a=a/100;
- while (dots_printed < a) {
- printf("*");
- ++dots_printed;
- fflush(stdout);
- }
- }
+ static char dots[] =
+ "**************************************************";
+ char dots_printed[51];
+ char fmt[42];
+ unsigned long a;
+
+ if (curr >= cmax) {
+ sln_printf("\r%79s\r","");
+ status_line(ipc->ServInfo.humannode, ipc->ServInfo.site_location,
+ room_name, secure, 0);
+ } else {
+ /* a will be range 0-50 rather than 0-100 */
+ a=(curr * 50) / cmax;
+ sprintf(fmt, "[%%s%%%lds] %%3ld%%%% %%10ld/%%10ld\r", 50 - a);
+ strncpy(dots_printed, dots, a);
+ dots_printed[a] = 0;
+ sln_printf(fmt, dots_printed, "",
+ curr * 100 / cmax, curr, cmax);
+ sln_flush();
}
+}
/*
* NOT the same locate_host() in locate_host.c. This one just does a
* 'who am i' to try to discover where the user is...
*/
-void locate_host(char *hbuf)
+void locate_host(CtdlIPC* ipc, char *hbuf)
{
- char buf[256];
+#ifndef HAVE_UTMP_H
+ char buf[SIZ];
FILE *who;
int a,b;
who = (FILE *)popen("who am i","r");
if (who==NULL) {
- strcpy(hbuf,serv_info.serv_fqdn);
+ strcpy(hbuf, ipc->ServInfo.fqdn);
return;
- }
- fgets(buf,256,who);
+ }
+ fgets(buf,sizeof buf,who);
pclose(who);
b = 0;
- for (a=0; a<strlen(buf); ++a) {
+ for (a=0; !IsEmptyStr(&buf[a]); ++a) {
if ((buf[a]=='(')||(buf[a]==')')) ++b;
- }
+ }
if (b<2) {
- strcpy(hbuf,serv_info.serv_fqdn);
+ strcpy(hbuf, ipc->ServInfo.fqdn);
return;
- }
+ }
for (a=0; a<strlen(buf); ++a) {
if (buf[a]=='(') {
strcpy(buf,&buf[a+1]);
- }
}
+ }
for (a=0; a<strlen(buf); ++a) {
if (buf[a]==')') buf[a] = 0;
- }
+ }
- if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
+ if (IsEmptyStr(buf)) strcpy(hbuf, ipc->ServInfo.fqdn);
else strncpy(hbuf,buf,24);
+#else
+ char *tty = ttyname(0);
+#ifdef HAVE_GETUTXLINE
+ struct utmpx ut, *put;
+#else
+ struct utmp ut, *put;
+#endif
+
+ if (tty == NULL) {
+ fail:
+ safestrncpy(hbuf, ipc->ServInfo.fqdn, 24);
+ return;
+ }
+
+ if (strncmp(tty, "/dev/", 5))
+ goto fail;
+
+ safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
+
+#ifdef HAVE_GETUTXLINE /* Solaris uses this */
+ if ((put = getutxline(&ut)) == NULL)
+#else
+ if ((put = getutline(&ut)) == NULL)
+#endif
+ goto fail;
+
+#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
+ if (put->ut_type == USER_PROCESS) {
+#endif
+#if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
+ if (*put->ut_host)
+ safestrncpy(hbuf, put->ut_host, 24);
+ else
+#endif
+ safestrncpy(hbuf, put->ut_line, 24);
+#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
}
+ else goto fail;
+#endif
+#endif /* HAVE_UTMP_H */
+}
/*
* miscellaneous server commands (testing, etc.)
*/
-void misc_server_cmd(char *cmd) {
- char buf[256];
+void misc_server_cmd(CtdlIPC *ipc, char *cmd) {
+ char buf[SIZ];
- serv_puts(cmd);
- serv_gets(buf);
- printf("%s\n",buf);
+ CtdlIPC_chat_send(ipc, cmd);
+ CtdlIPC_chat_recv(ipc, buf);
+ scr_printf("%s\n",buf);
if (buf[0]=='1') {
- while (serv_gets(buf), strcmp(buf,"000")) {
- printf("%s\n",buf);
- }
- return;
+ set_keepalives(KA_HALF);
+ while (CtdlIPC_chat_recv(ipc, buf), strcmp(buf,"000")) {
+ scr_printf("%s\n",buf);
}
+ set_keepalives(KA_YES);
+ return;
+ }
if (buf[0]=='4') {
do {
newprompt("> ",buf,255);
- serv_puts(buf);
- } while(strcmp(buf,"000"));
+ CtdlIPC_chat_send(ipc, buf);
+ } while(strcmp(buf,"000"));
return;
- }
}
+}
/*
*/
while (ch=getc(fp), ch>=0) {
cksum = (cksum + ch);
- }
+ }
fclose(fp);
return(cksum);
- }
+}
/*
* nuke a directory and its contents
{
DIR *dp;
struct dirent *d;
- char filename[256];
+ char filename[SIZ];
dp = opendir(dirname);
if (dp == NULL) {
return(errno);
- }
+ }
while (d = readdir(dp), d != NULL) {
- sprintf(filename, "%s/%s", dirname, d->d_name);
+ snprintf(filename, sizeof filename, "%s/%s",
+ dirname, d->d_name);
unlink(filename);
- }
+ }
closedir(dp);
return(rmdir(dirname));
- }
+}