#define bool int
-#define xstrncpy(d_,s_,l_) do { char* dst_=d_; dst_[0]='\0'; strncat((dst_),(s_),(l_)-1); } while(0)
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
typedef void Lang_function __P((FILE *));
#define MAIL_PROGRAM_NAME "/bin/mail"
#endif
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
+
static const char *my_name;
static char *the_date;
static char *the_user;
/* the_user */
the_user_len = strlen(temp);
the_user = alloc_string(the_user_len + 1);
- strncpy(the_user, the_user_len, temp);
+ xstrncpy(the_user, the_user_len, temp);
/* alloc the_string */
the_string_len = 3 + prefix_length + the_user_len + date_length;
the_string = alloc_string(the_string_len);
temp_len = the_string_len;
temp = the_string;
- strncpy(temp, temp_len, FROM_PREFIX);
+ xstrncpy(temp, temp_len, FROM_PREFIX);
temp = &temp[prefix_length];
*temp++ = ' ';
temp_len -= prefix_length + 1;
- strncpy(temp, temp_len, the_user);
+ xstrncpy(temp, temp_len, the_user);
temp = &temp[the_user_len];
*temp++ = ' ';
temp_len -= the_user_len + 1;
- strncpy(temp, temp_len, the_date);
+ xstrncpy(temp, temp_len, the_date);
result = new_list();
result->string = the_string;
}
*next_line = new_list();
(*next_line)->string = alloc_string((size_t) length);
- strncpy(((*next_line)->string), length, line);
+ xstrncpy(((*next_line)->string), length, line);
next_line = &((*next_line)->continuation);
*next_line = NIL;
the_header = read_header();
command_line_len = name_length + args_size(the_header);
command_line = alloc_string(command_line_len);
- strncpy(command_line, command_line_len, mail_program_name);
+ xstrncpy(command_line, command_line_len, mail_program_name);
parse_header(the_header, &command_line[name_length]);
the_pipe = popen(command_line, "w");
#include <signal.h>
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
+
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
!defined(INTERNET_DOMAIN_SOCKETS)
int main(int argc, char *argv[])
break;
case 'r':
GET_ARGUMENT(remotearg, "-r");
- strncpy(remotepath, remotearg, sizeof(remotepath));
+ xstrncpy(remotepath, remotearg, sizeof(remotepath));
remotepath[sizeof(remotepath)-1]='\0';
rflg = 1;
break;
* to this machine */
if ((ptr = getenv("GNU_NODE")) != NULL) {
/* user specified a path */
- strncpy(remotepath, ptr, sizeof(remotepath)-1);
+ xstrncpy(remotepath, ptr, sizeof(remotepath)-1);
remotepath[sizeof(remotepath)-1]='\0';
}
}
#include <string.h>
#endif /* HAVE_STRING_H */
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
+
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
!defined(INTERNET_DOMAIN_SOCKETS)
}
/* if */
msgctl(ipc_qid, IPC_STAT, &msg_st);
- strncpy(buf, msgp->mtext, len);
+ xstrncpy(buf, msgp->mtext, len);
/* terminate buf */
buf[len] = '\0';
struct re_pattern_buffer *regexp);
#endif
+
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
+
int verbose = 0;
#ifdef MAIL_USE_POP
int reverse = 0;
int len1 = strlen(s1), len2 = strlen(s2), len3 = strlen(s3);
char *result = (char *)xmalloc(len1 + len2 + len3 + 1);
- strncpy(result, s1, len1+1);
- strncpy(result + len1, s2, len2+1);
- strncpy(result + len1 + len2, s3, len3+1);
+ xstrncpy(result, s1, len1+1);
+ xstrncpy(result + len1, s2, len2+1);
+ xstrncpy(result + len1 + len2, s3, len3+1);
*(result + len1 + len2 + len3) = '\0';
return result;
int ret;
if (pop_retrieve_first(server, msgno, &line)) {
- strncpy(Errmsg, pop_error, sizeof(Errmsg));
+ xstrncpy(Errmsg, pop_error, sizeof(Errmsg));
Errmsg[sizeof(Errmsg) - 1] = '\0';
return (POP_ERROR);
}
}
if (ret) {
- strncpy(Errmsg, pop_error, sizeof(Errmsg));
+ xstrncpy(Errmsg, pop_error, sizeof(Errmsg));
Errmsg[sizeof(Errmsg) - 1] = '\0';
return (POP_ERROR);
}
int match = POP_DONE;
if (pop_top_first(server, msgno, lines, &line)) {
- strncpy(Errmsg, pop_error, sizeof(Errmsg));
+ xstrncpy(Errmsg, pop_error, sizeof(Errmsg));
Errmsg[sizeof(Errmsg) - 1] = '\0';
return (POP_ERROR);
}
}
if (ret) {
- strncpy(Errmsg, pop_error, sizeof(Errmsg));
+ xstrncpy(Errmsg, pop_error, sizeof(Errmsg));
Errmsg[sizeof(Errmsg) - 1] = '\0';
return (POP_ERROR);
}
# define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type)))
#endif
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
+
+
typedef int bool;
typedef void Lang_function(FILE *);
objdef = omethodtag;
methodlen = len;
grow_linebuffer(&token_name, methodlen + 1);
- strncpy(token_name.buffer, str, len);
+ xstrncpy(token_name.buffer, str, len);
token_name.buffer[methodlen] = '\0';
token_name.len = methodlen;
return TRUE;
(&token_name,
toklen +
1);
- strncpy
+ xstrncpy
(token_name.
buffer,
newlb.
/* save all values for later tagging */
grow_linebuffer(&tline, lb.len + 1);
- strncpy(tline.buffer, lb.buffer, lb.len);
+ xstrncpy(tline.buffer, lb.buffer, lb.len);
save_lineno = lineno;
save_lcno = linecharno;
else if (len + 1 > allocated)
last = xrnew(last, len + 1, char);
allocated = len + 1;
- strncpy(last, cp, len);
+ xstrncpy(last, cp, len);
last[len] = '\0';
}
}
else if (len + 1 > allocated)
last = xrnew(last, len + 1, char);
allocated = len + 1;
- strncpy(last, cp, len);
+ xstrncpy(last, cp, len);
last[len] = '\0';
}
}
/* Using "dig2" satisfies my debugger. Bleah. */
dig = *out - '0';
diglen = regs->end[dig] - regs->start[dig];
- strncpy(t, in + regs->start[dig], diglen);
+ xstrncpy(t, in + regs->start[dig], diglen);
t += diglen;
} else
*t++ = *out;
register char *dp;
dp = xnew(len + 1, char);
- strncpy(dp, cp, len);
+ xstrncpy(dp, cp, len);
dp[len] = '\0';
return dp;
}
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
+
/*
* Function: pop_open (char *host, char *username, char *password,
* int flags)
if (strncmp (fromserver, "+OK ", 4)) {
if (0 == strncmp (fromserver, "-ERR", 4)) {
- strncpy (pop_error, fromserver, ERROR_MAX);
+ xstrncpy (pop_error, fromserver, ERROR_MAX);
} else {
strcpy (pop_error,
"Unexpected response from POP "
}
if (strncmp (fromserver, "+OK ", 4)) {
if (! strncmp (fromserver, "-ERR", 4)) {
- strncpy (pop_error, fromserver, ERROR_MAX);
+ xstrncpy (pop_error, fromserver, ERROR_MAX);
} else {
strcpy (pop_error,
"Unexpected response from "
}
if (0 == strncmp (*response, "-ERR", 4)) {
- strncpy (pop_error, *response, ERROR_MAX);
+ xstrncpy (pop_error, *response, ERROR_MAX);
return (-1);
} else if (0 == strncmp (*response, "+OK", 3)) {
for (*response += 3; **response == ' ';
return (-1);
if (! strncmp (fromserver, "-ERR", 4)) {
- strncpy (pop_error, fromserver, ERROR_MAX);
+ xstrncpy (pop_error, fromserver, ERROR_MAX);
return (-1);
} else if (strncmp (fromserver, "+OK ", 4)) {
strcpy (pop_error, "Unexpected response from server in pop_last");
if (! strncmp (fromline, "+OK", 3))
return (0);
else if (! strncmp (fromline, "-ERR", 4)) {
- strncpy (pop_error, fromline, ERROR_MAX);
+ xstrncpy (pop_error, fromline, ERROR_MAX);
pop_error[ERROR_MAX-1] = '\0';
return (-1);
} else {
static void yow(FILE * fp);
static void setup_yow(FILE * fp);
+#define xstrncpy(d_,s_,l_) \
+ do { \
+ char* dst_=d_; \
+ dst_[0]='\0'; \
+ strncat((dst_),(s_),(l_)-1); \
+ } while(0)
+
+
int
main(int argc, char *argv[])
{
char file[BUFSIZ];
if (argc > 2 && !strcmp(argv[1], "-f")) {
- strncpy(file, argv[2], sizeof(file)-1);
+ xstrncpy(file, argv[2], sizeof(file)-1);
file[sizeof(file)-1]='\0';
} else {
#ifdef PATH_DATA
/* invocation-name includes a directory component -- presumably it
is relative to cwd, not $PATH */
assert(strlen(dir) < sizeof(exe_path));
- strncpy(exe_path, dir, sizeof(exe_path)-1);
+ xstrncpy(exe_path, dir, sizeof(exe_path));
exe_path[sizeof(exe_path)-1]='\0';
} else {
const char *path = getenv("PATH");
remain--;
}
if (remain > 0) {
- strncpy(w, name, remain);
+ xstrncpy(w, name, remain);
w[remain]='\0';
}
return Ffile_name_directory(filename);
}
\f
-static char *file_name_as_directory(char *out, char *in)
+static char *file_name_as_directory(char *out, const char *in, size_t len)
{
/* This function cannot GC */
int size = strlen(in);
if (size == 0) {
+ assert(len >= 3);
out[0] = '.';
out[1] = DIRECTORY_SEP;
out[2] = '\0';
} else {
- strcpy(out, in);
+ xstrncpy(out, in, len);
/* Append a slash if necessary */
if (!IS_ANY_SEP(out[size - 1])) {
out[size] = DIRECTORY_SEP;
(filename))
{
/* This function can GC. GC checked 2000-07-28 ben */
- char *buf;
- Lisp_Object handler;
+ size_t len = 0;
+ char *buf = NULL;
+ Lisp_Object handler = Qnil;
CHECK_STRING(filename);
return call2_check_string(handler, Qfile_name_as_directory,
filename);
- buf = (char *)alloca(XSTRING_LENGTH(filename) + 10);
+ len = XSTRING_LENGTH(filename) + 10;
+ buf = (char *)alloca(len);
return build_string(file_name_as_directory
- (buf, (char *)XSTRING_DATA(filename)));
+ (buf, (char*)XSTRING_DATA(filename), len));
}
\f
/*
* Value is nonzero if the string output is different from the input.
*/
-static int directory_file_name(const char *src, char *dst)
+static int directory_file_name(const char *src, char *dst, size_t len)
{
/* This function cannot GC */
long slen = strlen(src);
/* Process as Unix format: just remove any final slash.
But leave "/" unchanged; do not change it to "". */
- strcpy(dst, src);
+ xstrncpy(dst, src, len);
if (slen > 1 && IS_DIRECTORY_SEP(dst[slen - 1])
)
dst[slen - 1] = 0;
(directory))
{
/* This function can GC. GC checked 2000-07-28 ben */
- char *buf;
+ size_t len = 0;
+ char *buf = NULL;
Lisp_Object handler;
CHECK_STRING(directory);
if (!NILP(handler))
return call2_check_string(handler, Qdirectory_file_name,
directory);
- buf = (char *)alloca(XSTRING_LENGTH(directory) + 20);
- directory_file_name((char *)XSTRING_DATA(directory), buf);
+ len = XSTRING_LENGTH(directory) + 20;
+ buf = (char *)alloca(len);
+ directory_file_name((char *)XSTRING_DATA(directory), buf, len);
return build_string(buf);
}
\f
if (newdir) {
if (nm[0] == 0 || IS_DIRECTORY_SEP(nm[0]))
- strcpy((char *)target, (char *)newdir);
+ xstrncpy((char *)target, (char *)newdir, tlen);
else
- file_name_as_directory((char *)target, (char *)newdir);
+ file_name_as_directory((char *)target, (char *)newdir, tlen);
}
- strcat((char *)target, (char *)nm);
+ xstrncat((char *)target, (char *)nm, tlen);
/* ASSERT (IS_DIRECTORY_SEP (target[0])) if not VMS */
Bufbyte *target = 0;
int total = 0;
int substituted = 0;
+ size_t avail = 0;
Bufbyte *xnm;
Lisp_Object handler;
/* If substitution required, recopy the filename and do it */
/* Make space in stack frame for the new copy */
- xnm = (Bufbyte *) alloca(XSTRING_LENGTH(filename) + total + 1);
+ avail = XSTRING_LENGTH(filename) + total + 1;
+ xnm = (Bufbyte *) alloca(avail);
x = xnm;
/* Copy the rest of the name through, replacing $ constructs with values */
for (p = nm; *p;)
- if (*p != '$')
+ if (*p != '$') {
*x++ = *p++;
- else {
+ avail--;
+ } else {
p++;
if (p == endp)
goto badsubst;
else if (*p == '$') {
*x++ = *p++;
+ avail--;
continue;
} else if (*p == '{') {
o = ++p;
if (!o)
goto badvar;
- strcpy((char *)x, (char *)o);
+ xstrncpy((char *)x, (char *)o, avail);
x += strlen((char *)o);
+ avail -= strlen((char *)o);
}
*x = 0;
# endif /* ERROR_CHECK_MALLOC */
#endif /* BDWGC */
+\f
+/* str funs */
+#define xstrlen strlen
+#define xstrcmp strcmp
+#define xstrncmp strncmp
+#define xstrncat strncat
+
+extern_inline char*
+xstrncpy(char* target, const char*source, size_t len)
+ __attribute__((always_inline));
+extern_inline char*
+xstrncpy(char* target, const char*source, size_t len)
+{
+ *target ='\0';
+ return strncat(target,source,len-1);
+}
+
+#if !defined(FORBID_STRCPY)
+# define xstrcat strcat
+# define xstrcpy strcpy
+# if defined(HAVE_STPCPY)
+# define xstpcpy stpcpy
+# else
+extern_inline char*
+xstpcpy(char *target, const char *source)
+ __attribute__((always_inline));
+extern_inline char*
+xstpcpy(char *target, const char *source)
+{
+ char *p = target;
+ size_t len = xstrlen(source);
+
+ strcpy(target, source);
+ p += len;
+ return p;
+}
+# endif
+#else
+# if defined(strcpy)
+# undef strcpy
+# endif
+# define strcpy no_strcpy
+extern_inline char*
+no_strcpy(char*,const char*)
+ __attribute__((always_inline));
+extern_inline char*
+no_strcpy(char * SXE_UNUSED(target),const char * SXE_UNUSED(source))
+{
+ assert(0);
+ return NULL;
+}
+# if defined(strcat)
+# undef strcat
+# endif
+# define strcat no_strcat
+extern_inline char*
+no_strcat(char*,const char*)
+ __attribute__((always_inline));
+extern_inline char*
+no_strcat(char * SXE_UNUSED(target), const char* SXE_UNUSED(source))
+{
+ assert(0);
+ return NULL;
+}
+# if defined(stpcpy)
+# undef stpcpy
+# endif
+# define stpcpy no_stpcpy
+# define xstpcpy no_stpcpy
+extern_inline char*
+no_stpcpy(char*,const char*)
+ __attribute__((always_inline));
+extern_inline char*
+no_stpcpy(char* SXE_UNUSED(target),const char* SXE_UNUSED(source))
+{
+ assert(0);
+ return NULL;
+}
+#endif
+
+
+#if defined HAVE_STPNCPY
+# define xstpncpy stpncpy
+#else
+extern_inline char*
+xstpncpy(char *target, const char *source, size_t len)
+ __attribute__((always_inline));
+extern_inline char*
+xstpncpy(char *target, const char *source, size_t len)
+{
+ char *p = target;
+ xstrncpy(target, source, len);
+ p += len;
+ return p;
+}
+#endif /* !HAVE_STPNCPY */
+
+#define xmemcmp memcmp
+#define xmemcpy memcpy
+
+
+
+extern_inline size_t
+xmin_size_t(size_t a, size_t b)
+ __attribute__((always_inline));
+extern_inline size_t
+xmin_size_t(size_t a, size_t b)
+{
+ if (a < b) {
+ return a;
+ } else {
+ return b;
+ }
+}
+
#endif
char *xrealpath(const char *path, char restrict resolved_path[]);
#endif
-extern_inline size_t xmin_size_t(size_t a, size_t b);
extern_inline void x__dirname(char *restrict res, const char *file, size_t len);
extern_inline size_t x__dirlen(const char *file, size_t len);
extern_inline char *xdirname(const char *file);
-\f
-/* str funs */
-/* thought these were defined already :O */
-#define xstrlen strlen
-#define xstrcmp strcmp
-#define xstrcat strcat
-#define xstrncmp strncmp
-#define xstrncpy strncpy
-#define xstrncat strncat
-#if defined HAVE_STPCPY
-# define xstpcpy stpcpy
-#else
-extern_inline char*
-xstpcpy(char *target, const char *source)
- __attribute__((always_inline));
-extern_inline char*
-xstpcpy(char *target, const char *source)
-{
- char *p = target;
- size_t len = xstrlen(source);
-
- strcpy(target, source);
- p += len;
- return p;
-}
-#endif /* !HAVE_STPCPY */
-#if defined HAVE_STPNCPY
-# define xstpncpy stpncpy
-#else
-extern_inline char*
-xstpncpy(char *target, const char *source, size_t len)
- __attribute__((always_inline));
-extern_inline char*
-xstpncpy(char *target, const char *source, size_t len)
-{
- char *p = target;
- strncpy(target, source, len);
- p += len;
- return p;
-}
-#endif /* !HAVE_STPNCPY */
-
-#define xmemcmp memcmp
-#define xmemcpy memcpy
-
-extern_inline size_t
-xmin_size_t(size_t a, size_t b)
-{
- if (a < b) {
- return a;
- } else {
- return b;
- }
-}
-
\f
/* big dirname magic, some of it stolen from dirname.c from coreutils 6.9 */
/* POSIX says:
#define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
#endif
+extern_inline size_t
+x__dirlen(const char *file, size_t len)
+ __attribute__((always_inline));
extern_inline size_t
x__dirlen(const char *file, size_t len)
{
return len;
}
+extern_inline void
+x__dirname(char *restrict res, const char *file, size_t len)
+ __attribute__((always_inline));
#if defined(HAVE_DIRNAME) && defined(DIRNAME_SIDE_EFFECT)
extern_inline void
x__dirname(char *restrict res, const char *file, size_t len)
}
#endif
+extern_inline char*
+xdirname(const char *file)
+ __attribute__((always_inline));
extern_inline char*
xdirname(const char *file)
{