gen_build_files.sh uses bashism, document it
[oweals/busybox.git] / runit / runit_lib.c
index fcb66c3db77062128d82d58701b5e4114d01f35c..ec18b5edde54caff64018b8d7cd1fb33f6d51154 100644 (file)
@@ -25,7 +25,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/* Busyboxed by Denis Vlasenko <vda.linux@googlemail.com> */
+/* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */
 /* Collected into one file from runit's many tiny files */
 /* TODO: review, eliminate unneeded stuff, move good stuff to libbb */
 
@@ -34,8 +34,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "libbb.h"
 #include "runit_lib.h"
 
-/*** byte_chr.c ***/
-
+#ifdef UNUSED
 unsigned byte_chr(char *s,unsigned n,int c)
 {
        char ch;
@@ -52,62 +51,8 @@ unsigned byte_chr(char *s,unsigned n,int c)
        return t - s;
 }
 
-
-/*** coe.c ***/
-
-int coe(int fd)
-{
-       return fcntl(fd,F_SETFD,FD_CLOEXEC);
-}
-
-
-/*** fmt_ptime.c ***/
-
-void fmt_ptime30nul(char *s, struct taia *ta) {
-       struct tm *t;
-       unsigned long u;
-
-       if (ta->sec.x < 4611686018427387914ULL)
-               return; /* impossible? */
-       u = ta->sec.x -4611686018427387914ULL;
-       t = gmtime((time_t*)&u);
-       if (!t)
-               return; /* huh? */
-       //fmt_ulong(s, 1900 + t->tm_year);
-       //s[4] = '-'; fmt_uint0(&s[5], t->tm_mon+1, 2);
-       //s[7] = '-'; fmt_uint0(&s[8], t->tm_mday, 2);
-       //s[10] = '_'; fmt_uint0(&s[11], t->tm_hour, 2);
-       //s[13] = ':'; fmt_uint0(&s[14], t->tm_min, 2);
-       //s[16] = ':'; fmt_uint0(&s[17], t->tm_sec, 2);
-       //s[19] = '.'; fmt_uint0(&s[20], ta->nano, 9);
-       sprintf(s, "%04u-%02u-%02u_%02u:%02u:%02u.%09u",
-               (unsigned)(1900 + t->tm_year),
-               (unsigned)(t->tm_mon+1),
-               (unsigned)(t->tm_mday),
-               (unsigned)(t->tm_hour),
-               (unsigned)(t->tm_min),
-               (unsigned)(t->tm_sec),
-               (unsigned)(ta->nano)
-       );
-       /* 4+1 + 2+1 + 2+1 + 2+1 + 2+1 + 2+1 + 9 = */
-       /* 5   + 3   + 3   + 3   + 3   + 3   + 9 = */
-       /* 20 (up to '.' inclusive) + 9 (not including '\0') */
-}
-
-unsigned fmt_taia25(char *s, struct taia *t) {
-       static char pack[TAIA_PACK];
-
-       taia_pack(pack, t);
-       *s++ = '@';
-       bin2hex(s, pack, 12);
-       return 25;
-}
-
-
-/*** tai_pack.c ***/
-
 static /* as it isn't used anywhere else */
-void tai_pack(char *s,const struct tai *t)
+void tai_pack(char *s, const struct tai *t)
 {
        uint64_t x;
 
@@ -122,19 +67,6 @@ void tai_pack(char *s,const struct tai *t)
        s[0] = x;
 }
 
-
-#ifdef UNUSED
-/*** tai_sub.c ***/
-
-void tai_sub(struct tai *t, const struct tai *u, const struct tai *v)
-{
-       t->x = u->x - v->x;
-}
-#endif
-
-
-/*** tai_unpack.c ***/
-
 void tai_unpack(const char *s,struct tai *t)
 {
        uint64_t x;
@@ -151,8 +83,6 @@ void tai_unpack(const char *s,struct tai *t)
 }
 
 
-/*** taia_add.c ***/
-
 void taia_add(struct taia *t,const struct taia *u,const struct taia *v)
 {
        t->sec.x = u->sec.x + v->sec.x;
@@ -168,9 +98,6 @@ void taia_add(struct taia *t,const struct taia *u,const struct taia *v)
        }
 }
 
-
-/*** taia_less.c ***/
-
 int taia_less(const struct taia *t, const struct taia *u)
 {
        if (t->sec.x < u->sec.x) return 1;
@@ -180,9 +107,6 @@ int taia_less(const struct taia *t, const struct taia *u)
        return t->atto < u->atto;
 }
 
-
-/*** taia_now.c ***/
-
 void taia_now(struct taia *t)
 {
        struct timeval now;
@@ -192,9 +116,7 @@ void taia_now(struct taia *t)
        t->atto = 0;
 }
 
-
-/*** taia_pack.c ***/
-
+/* UNUSED
 void taia_pack(char *s, const struct taia *t)
 {
        unsigned long x;
@@ -213,9 +135,7 @@ void taia_pack(char *s, const struct taia *t)
        s[1] = x & 255; x >>= 8;
        s[0] = x;
 }
-
-
-/*** taia_sub.c ***/
+*/
 
 void taia_sub(struct taia *t, const struct taia *u, const struct taia *v)
 {
@@ -235,11 +155,7 @@ void taia_sub(struct taia *t, const struct taia *u, const struct taia *v)
        }
 }
 
-
-/*** taia_uint.c ***/
-
 /* XXX: breaks tai encapsulation */
-
 void taia_uint(struct taia *t, unsigned s)
 {
        t->sec.x = s;
@@ -247,16 +163,12 @@ void taia_uint(struct taia *t, unsigned s)
        t->atto = 0;
 }
 
-
-/*** iopause.c ***/
-
 static
 uint64_t taia2millisec(const struct taia *t)
 {
        return (t->sec.x * 1000) + (t->nano / 1000000);
 }
 
-
 void iopause(iopause_fd *x, unsigned len, struct taia *deadline, struct taia *stamp)
 {
        int millisecs;
@@ -282,77 +194,62 @@ void iopause(iopause_fd *x, unsigned len, struct taia *deadline, struct taia *st
        /* XXX: how to handle EAGAIN? are kernels really this dumb? */
        /* XXX: how to handle EINVAL? when exactly can this happen? */
 }
-
-
-/*** lock_ex.c ***/
+#endif
 
 int lock_ex(int fd)
 {
        return flock(fd,LOCK_EX);
 }
 
-
-/*** lock_exnb.c ***/
-
 int lock_exnb(int fd)
 {
        return flock(fd,LOCK_EX | LOCK_NB);
 }
 
-
-/*** open_append.c ***/
-
 int open_append(const char *fn)
 {
        return open(fn, O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600);
 }
 
-
-/*** open_read.c ***/
-
 int open_read(const char *fn)
 {
        return open(fn, O_RDONLY|O_NDELAY);
 }
 
-
-/*** open_trunc.c ***/
-
 int open_trunc(const char *fn)
 {
        return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644);
 }
 
-
-/*** open_write.c ***/
-
 int open_write(const char *fn)
 {
        return open(fn, O_WRONLY|O_NDELAY);
 }
 
-
-/*** pmatch.c ***/
-
-unsigned pmatch(const char *p, const char *s, unsigned len) {
+unsigned pmatch(const char *p, const char *s, unsigned len)
+{
        for (;;) {
                char c = *p++;
                if (!c) return !len;
                switch (c) {
                case '*':
-                       if (!(c = *p)) return 1;
+                       c = *p;
+                       if (!c) return 1;
                        for (;;) {
                                if (!len) return 0;
                                if (*s == c) break;
-                               ++s; --len;
+                               ++s;
+                               --len;
                        }
                        continue;
                case '+':
-                       if ((c = *p++) != *s) return 0;
+                       c = *p++;
+                       if (c != *s) return 0;
                        for (;;) {
                                if (!len) return 1;
                                if (*s != c) break;
-                               ++s; --len;
+                               ++s;
+                               --len;
                        }
                        continue;
                        /*
@@ -367,38 +264,10 @@ unsigned pmatch(const char *p, const char *s, unsigned len) {
                default:
                        if (!len) return 0;
                        if (*s != c) return 0;
-                       ++s; --len;
+                       ++s;
+                       --len;
                        continue;
                }
        }
        return 0;
 }
-
-
-#ifdef UNUSED
-/*** seek_set.c ***/
-
-int seek_set(int fd,seek_pos pos)
-{
-       if (lseek(fd,(off_t) pos,SEEK_SET) == -1) return -1; return 0;
-}
-#endif
-
-
-/*** str_chr.c ***/
-
-// strchrnul?
-unsigned str_chr(const char *s,int c)
-{
-       char ch;
-       const char *t;
-
-       ch = c;
-       t = s;
-       for (;;) {
-               if (!*t) break;
-               if (*t == ch) break;
-               ++t;
-       }
-       return t - s;
-}