Avoid using basename(), it's way too nasty from a portability

standpoint.

Change recvfile, sendfile -> tftp_* due to namespace collision problems.
This commit is contained in:
hpa 2001-11-12 05:57:29 +00:00
parent ba41bd7cea
commit 5b21a932a6
2 changed files with 16 additions and 14 deletions

View file

@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <syslog.h> #include <syslog.h>
#include <sys/types.h> /* FreeBSD 3.3 need this before regex.h */
#include <regex.h> #include <regex.h>
#include <syslog.h> #include <syslog.h>

View file

@ -70,7 +70,6 @@ static const char *rcsid UNUSED =
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <ctype.h> #include <ctype.h>
#define __USE_GNU /* Necessary for basename() on glibc systems */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <pwd.h> #include <pwd.h>
@ -81,6 +80,10 @@ static const char *rcsid UNUSED =
#include "recvfrom.h" #include "recvfrom.h"
#include "remap.h" #include "remap.h"
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h> /* Necessary for FIONBIO on Solaris */
#endif
#ifdef HAVE_TCPWRAPPERS #ifdef HAVE_TCPWRAPPERS
#include <tcpd.h> #include <tcpd.h>
@ -89,12 +92,6 @@ int allow_severity = -1; /* Don't log at all */
struct request_info wrap_request; struct request_info wrap_request;
#endif #endif
#ifdef HAVE_LIBGEN_H
#include <libgen.h> /* Necessary for basename() on Solaris */
#endif
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h> /* Necessary for FIONBIO on Solaris */
#endif
#define TIMEOUT 5 /* Default timeout (seconds) */ #define TIMEOUT 5 /* Default timeout (seconds) */
#define TRIES 4 /* Number of attempts to send each packet */ #define TRIES 4 /* Number of attempts to send each packet */
@ -211,11 +208,15 @@ main(int argc, char **argv)
int setrv; int setrv;
int timeout = 900; /* Default timeout */ int timeout = 900; /* Default timeout */
const char *user = "nobody"; /* Default user */ const char *user = "nobody"; /* Default user */
char *p;
#ifdef WITH_REGEX #ifdef WITH_REGEX
char *rewrite_file = NULL; char *rewrite_file = NULL;
#endif #endif
__progname = basename(argv[0]); /* basename() is way too much of a pain from a portability standpoint */
p = strrchr(argv[0], '/');
__progname = (p && p[1]) ? p+1 : argv[0];
openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);
@ -534,8 +535,8 @@ main(int argc, char **argv)
char *rewrite_access(char *, int); char *rewrite_access(char *, int);
int validate_access(char *, int, struct formats *); int validate_access(char *, int, struct formats *);
void sendfile(struct formats *, struct tftphdr *, int); void tftp_sendfile(struct formats *, struct tftphdr *, int);
void recvfile(struct formats *, struct tftphdr *, int); void tftp_recvfile(struct formats *, struct tftphdr *, int);
struct formats { struct formats {
const char *f_mode; const char *f_mode;
@ -545,8 +546,8 @@ struct formats {
void (*f_recv)(struct formats *, struct tftphdr *, int); void (*f_recv)(struct formats *, struct tftphdr *, int);
int f_convert; int f_convert;
} formats[] = { } formats[] = {
{ "netascii", rewrite_access, validate_access, sendfile, recvfile, 1 }, { "netascii", rewrite_access, validate_access, tftp_sendfile, tftp_recvfile, 1 },
{ "octet", rewrite_access, validate_access, sendfile, recvfile, 0 }, { "octet", rewrite_access, validate_access, tftp_sendfile, tftp_recvfile, 0 },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL, 0 }
}; };
@ -903,7 +904,7 @@ timer(int sig)
* Send the requested file. * Send the requested file.
*/ */
void void
sendfile(struct formats *pf, struct tftphdr *oap, int oacklen) tftp_sendfile(struct formats *pf, struct tftphdr *oap, int oacklen)
{ {
struct tftphdr *dp; struct tftphdr *dp;
struct tftphdr *ap; /* ack packet */ struct tftphdr *ap; /* ack packet */
@ -1011,7 +1012,7 @@ justquit(int sig)
* Receive a file. * Receive a file.
*/ */
void void
recvfile(struct formats *pf, struct tftphdr *oap, int oacklen) tftp_recvfile(struct formats *pf, struct tftphdr *oap, int oacklen)
{ {
struct tftphdr *dp; struct tftphdr *dp;
int n, size; int n, size;