aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-02-18 20:15:36 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-02-18 20:15:36 +0000
commitbed81910e74b39372bd30e1be55502754cf5e876 (patch)
tree4654251260c6a065178ab035453c4026c9de975f
parentaba90261a774cb31898563edbe16da780f7c738b (diff)
downloadbusybox-w32-bed81910e74b39372bd30e1be55502754cf5e876.tar.gz
busybox-w32-bed81910e74b39372bd30e1be55502754cf5e876.tar.bz2
busybox-w32-bed81910e74b39372bd30e1be55502754cf5e876.zip
A few more cleanups from Vladimir.
git-svn-id: svn://busybox.net/trunk/busybox@1853 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--utility.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/utility.c b/utility.c
index a38ecf080..65496b9f7 100644
--- a/utility.c
+++ b/utility.c
@@ -1388,15 +1388,14 @@ extern char * xstrndup (const char *s, int n) {
1388 if (s == NULL) 1388 if (s == NULL)
1389 error_msg_and_die("xstrndup bug"); 1389 error_msg_and_die("xstrndup bug");
1390 1390
1391 t = xmalloc(n+1); 1391 t = xmalloc(++n);
1392 strncpy(t,s,n); 1392
1393 t[n] = 0; 1393 return safe_strncpy(t,s,n);
1394
1395 return t;
1396} 1394}
1397#endif 1395#endif
1398 1396
1399#if defined BB_IFCONFIG || defined BB_ROUTE 1397#if defined BB_IFCONFIG || defined BB_ROUTE || defined BB_NFSMOUNT || \
1398 defined BB_FEATURE_MOUNT_LOOP
1400/* Like strncpy but make sure the resulting string is always 0 terminated. */ 1399/* Like strncpy but make sure the resulting string is always 0 terminated. */
1401extern char * safe_strncpy(char *dst, const char *src, size_t size) 1400extern char * safe_strncpy(char *dst, const char *src, size_t size)
1402{ 1401{
@@ -1457,8 +1456,7 @@ extern int set_loop(const char *device, const char *file, int offset,
1457 *loopro = (mode == O_RDONLY); 1456 *loopro = (mode == O_RDONLY);
1458 1457
1459 memset(&loopinfo, 0, sizeof(loopinfo)); 1458 memset(&loopinfo, 0, sizeof(loopinfo));
1460 strncpy(loopinfo.lo_name, file, LO_NAME_SIZE); 1459 safe_strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
1461 loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
1462 1460
1463 loopinfo.lo_offset = offset; 1461 loopinfo.lo_offset = offset;
1464 1462
@@ -1695,7 +1693,7 @@ FILE *wfopen(const char *path, const char *mode)
1695#if defined BB_HOSTNAME || defined BB_LOADACM || defined BB_MORE \ 1693#if defined BB_HOSTNAME || defined BB_LOADACM || defined BB_MORE \
1696 || defined BB_SED || defined BB_SH || defined BB_TAR || defined BB_UNIQ \ 1694 || defined BB_SED || defined BB_SH || defined BB_TAR || defined BB_UNIQ \
1697 || defined BB_WC || defined BB_CMP || defined BB_SORT || defined BB_WGET \ 1695 || defined BB_WC || defined BB_CMP || defined BB_SORT || defined BB_WGET \
1698 || defined BB_MOUNT 1696 || defined BB_MOUNT || defined BB_ROUTE
1699FILE *xfopen(const char *path, const char *mode) 1697FILE *xfopen(const char *path, const char *mode)
1700{ 1698{
1701 FILE *fp; 1699 FILE *fp;
@@ -1745,15 +1743,21 @@ unsigned long parse_number(const char *numstr,
1745 if (numstr == end) 1743 if (numstr == end)
1746 error_msg_and_die("invalid number `%s'", numstr); 1744 error_msg_and_die("invalid number `%s'", numstr);
1747 while (end[0] != '\0') { 1745 while (end[0] != '\0') {
1748 for (sm = suffixes; sm->suffix != NULL; sm++) { 1746 sm = suffixes;
1749 len = strlen(sm->suffix); 1747 while ( sm != 0 ) {
1750 if (strncmp(sm->suffix, end, len) == 0) { 1748 if(sm->suffix) {
1751 ret *= sm->mult; 1749 len = strlen(sm->suffix);
1752 end += len; 1750 if (strncmp(sm->suffix, end, len) == 0) {
1753 break; 1751 ret *= sm->mult;
1754 } 1752 end += len;
1753 break;
1754 }
1755 sm++;
1756
1757 } else
1758 sm = 0;
1755 } 1759 }
1756 if (sm->suffix == NULL) 1760 if (sm == 0)
1757 error_msg_and_die("invalid number `%s'", numstr); 1761 error_msg_and_die("invalid number `%s'", numstr);
1758 } 1762 }
1759 return ret; 1763 return ret;