correct a few protos and comments

saves 4 .text bytes and my nerves
This commit is contained in:
tg 2006-11-10 03:45:57 +00:00
parent f8e7fdbb71
commit d10dd31b9a
3 changed files with 27 additions and 44 deletions

12
funcs.c
View File

@ -5,7 +5,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.32 2006/11/09 23:19:52 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.33 2006/11/10 03:45:56 tg Exp $");
int int
c_cd(char **wp) c_cd(char **wp)
@ -178,13 +178,9 @@ c_pwd(char **wp)
NULL; NULL;
if (p && eaccess(p, R_OK) < 0) if (p && eaccess(p, R_OK) < 0)
p = NULL; p = NULL;
if (!p) { if (!p && !(p = ksh_get_wd(NULL))) {
p = ksh_get_wd(NULL, 0); bi_errorf("can't get current directory - %s", strerror(errno));
if (!p) { return 1;
bi_errorf("can't get current directory - %s",
strerror(errno));
return 1;
}
} }
shprintf("%s\n", p); shprintf("%s\n", p);
return 0; return 0;

51
misc.c
View File

@ -3,7 +3,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.29 2006/11/10 03:23:50 tg Exp $\t" __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.30 2006/11/10 03:45:57 tg Exp $\t"
MKSH_SH_H_ID); MKSH_SH_H_ID);
unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */ unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */
@ -747,7 +747,7 @@ xstrcmp(const void *p1, const void *p2)
return (strcmp(*(const char **)p1, *(const char **)p2)); return (strcmp(*(const char **)p1, *(const char **)p2));
} }
/* Initialize a Getopt structure */ /* Initialise a Getopt structure */
void void
ksh_getopt_reset(Getopt *go, int flags) ksh_getopt_reset(Getopt *go, int flags)
{ {
@ -962,7 +962,7 @@ print_columns(struct shf *shf, int n, char *(*func) (void *, int, char *, int),
} }
/* Strip any nul bytes from buf - returns new length (nbytes - # of nuls) */ /* Strip any nul bytes from buf - returns new length (nbytes - # of nuls) */
int void
strip_nuls(char *buf, int nbytes) strip_nuls(char *buf, int nbytes)
{ {
char *dst; char *dst;
@ -985,9 +985,7 @@ strip_nuls(char *buf, int nbytes)
dst += q - p; dst += q - p;
} }
*dst = '\0'; *dst = '\0';
return dst - buf;
} }
return nbytes;
} }
/* Like read(2), but if read fails due to non-blocking flag, resets flag /* Like read(2), but if read fails due to non-blocking flag, resets flag
@ -1001,12 +999,11 @@ blocking_read(int fd, char *buf, int nbytes)
while ((ret = read(fd, buf, nbytes)) < 0) { while ((ret = read(fd, buf, nbytes)) < 0) {
if (!tried_reset && errno == EAGAIN) { if (!tried_reset && errno == EAGAIN) {
int oerrno = errno;
if (reset_nonblock(fd) > 0) { if (reset_nonblock(fd) > 0) {
tried_reset = 1; tried_reset = 1;
continue; continue;
} }
errno = oerrno; errno = EAGAIN;
} }
break; break;
} }
@ -1035,29 +1032,18 @@ reset_nonblock(int fd)
/* Like getcwd(), except bsize is ignored if buf is 0 (PATH_MAX is used) */ /* Like getcwd(), except bsize is ignored if buf is 0 (PATH_MAX is used) */
char * char *
ksh_get_wd(char *buf, int bsize) ksh_get_wd(size_t *dlen)
{ {
char *b; char *ret, *b;
char *ret; size_t len = 0;
/* Note: we could just use plain getcwd(), but then we'd had to if ((ret = getcwd((b = alloc(PATH_MAX + 1, ATEMP)), PATH_MAX)))
* inject possibly allocated space into the ATEMP area. */ ret = aresize(b, len = (strlen(b) + 1), ATEMP);
/* Assume getcwd() available */ else
if (!buf) { afree(b, ATEMP);
bsize = PATH_MAX;
b = alloc(PATH_MAX + 1, ATEMP);
} else
b = buf;
ret = getcwd(b, bsize);
if (!buf) {
if (ret)
ret = aresize(b, strlen(b) + 1, ATEMP);
else
afree(b, ATEMP);
}
if (dlen)
*dlen = len;
return ret; return ret;
} }
@ -1221,13 +1207,14 @@ simplify_path(char *pathl)
void void
set_current_wd(char *pathl) set_current_wd(char *pathl)
{ {
int len; size_t len = 1;
char *p = pathl; char *p = pathl;
if (!p && !(p = ksh_get_wd(NULL, 0))) if (p == NULL) {
p = null; if ((p = ksh_get_wd(&len)) == NULL)
p = null;
len = strlen(p) + 1; } else
len = strlen(p) + 1;
if (len > current_wd_size) if (len > current_wd_size)
current_wd = aresize(current_wd, current_wd_size = len, APERM); current_wd = aresize(current_wd, current_wd_size = len, APERM);

8
sh.h
View File

@ -8,7 +8,7 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.72 2006/11/10 03:23:50 tg Exp $" #define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.73 2006/11/10 03:45:57 tg Exp $"
#define MKSH_VERSION "R29 2006/11/10" #define MKSH_VERSION "R29 2006/11/10"
#if HAVE_SYS_PARAM_H #if HAVE_SYS_PARAM_H
@ -454,7 +454,7 @@ EXTERN Tflag builtin_flag; /* flags of called builtin (SPEC_BI, etc.) */
/* current working directory, and size of memory allocated for same */ /* current working directory, and size of memory allocated for same */
EXTERN char *current_wd; EXTERN char *current_wd;
EXTERN int current_wd_size; EXTERN size_t current_wd_size;
/* Minimum required space to work with on a line - if the prompt leaves less /* Minimum required space to work with on a line - if the prompt leaves less
* space than this on a line, the prompt is truncated. * space than this on a line, the prompt is truncated.
@ -1237,10 +1237,10 @@ int ksh_getopt(char **, Getopt *, const char *);
void print_value_quoted(const char *); void print_value_quoted(const char *);
void print_columns(struct shf *, int, char *(*)(void *, int, char *, int), void print_columns(struct shf *, int, char *(*)(void *, int, char *, int),
void *, int, int prefcol); void *, int, int prefcol);
int strip_nuls(char *, int); void strip_nuls(char *, int);
int blocking_read(int, char *, int); int blocking_read(int, char *, int);
int reset_nonblock(int); int reset_nonblock(int);
char *ksh_get_wd(char *, int); char *ksh_get_wd(size_t *);
int make_path(const char *, const char *, char **, XString *, int *); int make_path(const char *, const char *, char **, XString *, int *);
void simplify_path(char *); void simplify_path(char *);
char *get_phys_path(const char *); char *get_phys_path(const char *);