[hackers] [sbase] sort: linebuf is no global || Jakob Kramer

2014-05-03 Thread git
commit c4e5354a32a311b0a0636ff7223d914ef7926c36
Author: Jakob Kramer 
Date:   Sat May 3 18:28:20 2014 +0200

sort: linebuf is no global

diff --git a/sort.c b/sort.c
index 6c3b6f9..4b98cd9 100644
--- a/sort.c
+++ b/sort.c
@@ -35,8 +35,6 @@ static bool rflag = false;
 static bool uflag = false;
 static bool nflag = false;
 
-static struct linebuf linebuf = EMPTY_LINEBUF;
-
 static void
 usage(void)
 {
@@ -48,6 +46,7 @@ main(int argc, char *argv[])
 {
long i;
FILE *fp;
+   struct linebuf linebuf = EMPTY_LINEBUF;
 
ARGBEGIN {
case 'n':




[hackers] [sbase] sort: don't repeat skipping columns logic || Jakob Kramer

2014-05-03 Thread git
commit 56b9a26de9835bd1f778a142d3c8aa8710b81525
Author: Jakob Kramer 
Date:   Sat May 3 18:34:51 2014 +0200

sort: don't repeat skipping columns logic

diff --git a/sort.c b/sort.c
index 4b98cd9..be1f699 100644
--- a/sort.c
+++ b/sort.c
@@ -29,6 +29,7 @@ static int linecmp(const char **, const char **);
 static char *next_nonblank(char *);
 static char *next_blank(char *);
 static int parse_keydef(struct keydef *, char *);
+static char *skip_columns(char *, size_t);
 static char *columns(char *, const struct keydef *);
 
 static bool rflag = false;
@@ -194,6 +195,20 @@ next_blank(char *s)
 }
 
 static char *
+skip_columns(char *s, size_t n)
+{
+   size_t i;
+
+   for(i = 0; i < n; i++) {
+   if(i != 0)
+   s = next_blank(s);
+   s = next_nonblank(s);
+   }
+
+   return s;
+}
+
+static char *
 columns(char *line, const struct keydef *kd)
 {
char *rest;
@@ -201,31 +216,23 @@ columns(char *line, const struct keydef *kd)
char *res;
unsigned int i;
 
-   rest = line;
-   for(i = 0; i < kd->start_column; i++) {
-   if(i != 0)
-   rest = next_blank(rest);
-   rest = next_nonblank(rest);
-   }
+   rest = skip_columns(line, kd->start_column);
for(i = 1; i < kd->start_char && *rest && !isblank(*rest); i++)
rest++;
start = rest;
 
if(kd->end_column) {
-   rest = line;
-   for(i = 0; i < kd->end_column; i++) {
-   if(i != 0)
-   rest = next_blank(rest);
-   rest = next_nonblank(rest);
-   }
+   rest = skip_columns(line, kd->end_column);
if(kd->end_char)
for(i = 1; i < kd->end_char && *rest && 
!isblank(*rest); i++)
rest++;
else
rest = next_blank(rest);
end = rest - 1;
-   } else
+   } else {
end = rest + strlen(rest);
+   }
+
if((res = strndup(start, end - start)) == NULL)
enprintf(2, "strndup:");
return res;




[hackers] [sbase] sort: simplify skip_columns || Jakob Kramer

2014-05-03 Thread git
commit a2da9edb9950366e2267ffa9274753a9eb26449c
Author: Jakob Kramer 
Date:   Sat May 3 20:39:45 2014 +0200

sort: simplify skip_columns

diff --git a/sort.c b/sort.c
index 5af81d2..9ab58d8 100644
--- a/sort.c
+++ b/sort.c
@@ -206,16 +206,10 @@ skip_columns(char *s, size_t n)
size_t i;
 
for(i = 0; i < n; i++) {
-   if(bflag) {
-   if(i != 0)
-   s = next_blank(s);
+   if(i > 0)
+   s = end_column(s);
+   if(bflag)
s = next_nonblank(s);
-   } else {
-   if(i == 0)
-   continue;
-   s = next_nonblank(s);
-   s = next_blank(s);
-   }
}
 
return s;




[hackers] [sbase] sort: replace loop with MIN() || Jakob Kramer

2014-05-03 Thread git
commit e535e8d88a12459ddbf3542af6483b242cbd09e0
Author: Jakob Kramer 
Date:   Sat May 3 18:52:18 2014 +0200

sort: replace loop with MIN()

diff --git a/sort.c b/sort.c
index deab422..3614853 100644
--- a/sort.c
+++ b/sort.c
@@ -213,17 +213,14 @@ columns(char *line, const struct keydef *kd)
 {
char *start, *end;
char *res;
-   unsigned int i;
 
start = skip_columns(line, kd->start_column);
-   for(i = 1; i < kd->start_char && *start && !isblank(*start); i++)
-   start++;
+   start += MIN(kd->start_char, next_blank(start) - start) - 1;
 
if(kd->end_column) {
end = skip_columns(line, kd->end_column);
if(kd->end_char)
-   for(i = 1; i < kd->end_char && *end && !isblank(*end); 
i++)
-   end++;
+   end += MIN(kd->end_char, next_blank(end) - end);
else
end = next_blank(end);
} else {




[hackers] [sbase] sort: add -b flag; don't use it as default || Jakob Kramer

2014-05-03 Thread git
commit d965985a5219ed5dbe09fc83177beb5bb56f73fd
Author: Jakob Kramer 
Date:   Sat May 3 20:24:08 2014 +0200

sort: add -b flag; don't use it as default

diff --git a/sort.c b/sort.c
index 63b9509..5af81d2 100644
--- a/sort.c
+++ b/sort.c
@@ -30,11 +30,13 @@ static char *next_nonblank(char *);
 static char *next_blank(char *);
 static int parse_keydef(struct keydef *, char *);
 static char *skip_columns(char *, size_t);
+static char *end_column(char *);
 static char *columns(char *, const struct keydef *);
 
 static bool rflag = false;
 static bool uflag = false;
 static bool nflag = false;
+static bool bflag = false;
 
 static void
 usage(void)
@@ -59,6 +61,9 @@ main(int argc, char *argv[])
case 'u':
uflag = true;
break;
+   case 'b':
+   bflag = true;
+   break;
case 'k':
addkeydef(EARGF(usage()));
break;
@@ -169,7 +174,7 @@ parse_keydef(struct keydef *kd, char *s)
kd->start_char = strtoul(rest+1, &rest, 10);
if(*rest == ',') {
kd->end_column = strtoul(rest+1, &rest, 10);
-   if(kd->end_column < kd->start_column)
+   if(kd->end_column && kd->end_column < kd->start_column)
enprintf(2, ",%u is too small
", kd->end_column);
if(*rest == '.')
kd->end_char = strtoul(rest+1, &rest, 10);
@@ -201,29 +206,45 @@ skip_columns(char *s, size_t n)
size_t i;
 
for(i = 0; i < n; i++) {
-   if(i != 0)
+   if(bflag) {
+   if(i != 0)
+   s = next_blank(s);
+   s = next_nonblank(s);
+   } else {
+   if(i == 0)
+   continue;
+   s = next_nonblank(s);
s = next_blank(s);
-   s = next_nonblank(s);
+   }
}
 
return s;
 }
 
 static char *
+end_column(char *s)
+{
+   if(bflag)
+   return next_blank(s);
+   else
+   return next_blank(next_nonblank(s));
+}
+
+static char *
 columns(char *line, const struct keydef *kd)
 {
char *start, *end;
char *res;
 
start = skip_columns(line, kd->start_column);
-   start += MIN(kd->start_char, next_blank(start) - start) - 1;
+   start += MIN(kd->start_char, end_column(start) - start) - 1;
 
if(kd->end_column) {
end = skip_columns(line, kd->end_column);
if(kd->end_char)
-   end += MIN(kd->end_char, next_blank(end) - end);
+   end += MIN(kd->end_char, end_column(end) - end);
else
-   end = next_blank(end);
+   end = end_column(end);
} else {
end = line + strlen(line);
}




[hackers] [sbase] sort: don't evaluate if clause || Jakob Kramer

2014-05-03 Thread git
commit a62a2197a8e49f2c40f6c7c10a28339f1dd28dbe
Author: Jakob Kramer 
Date:   Sat May 3 19:06:20 2014 +0200

sort: don't evaluate if clause

this fixes that you could specify a key
definition like "-k 1.2.3", which is incorrect.

diff --git a/sort.c b/sort.c
index 3614853..63b9509 100644
--- a/sort.c
+++ b/sort.c
@@ -103,7 +103,7 @@ addkeydef(char *def)
if(!head)
head = node;
if(parse_keydef(&node->keydef, def))
-   enprintf(2, "parse_keydef:");
+   enprintf(2, "faulty key definition
");
if(curr)
curr->next = node;
node->next = NULL;
@@ -155,6 +155,7 @@ static int
 parse_keydef(struct keydef *kd, char *s)
 {
char *rest = s;
+
kd->start_column = 1;
kd->start_char = 1;
/* 0 means end of line */
@@ -170,9 +171,9 @@ parse_keydef(struct keydef *kd, char *s)
kd->end_column = strtoul(rest+1, &rest, 10);
if(kd->end_column < kd->start_column)
enprintf(2, ",%u is too small
", kd->end_column);
+   if(*rest == '.')
+   kd->end_char = strtoul(rest+1, &rest, 10);
}
-   if(*rest == '.')
-   kd->end_char = strtoul(rest+1, &rest, 10);
if(*rest != '



[hackers] [sbase] sort: remove 'rest' variable || Jakob Kramer

2014-05-03 Thread git
commit 56e1616486154d0d15fe04567a16328b2a94d51a
Author: Jakob Kramer 
Date:   Sat May 3 18:44:10 2014 +0200

sort: remove 'rest' variable

diff --git a/sort.c b/sort.c
index be1f699..deab422 100644
--- a/sort.c
+++ b/sort.c
@@ -211,26 +211,23 @@ skip_columns(char *s, size_t n)
 static char *
 columns(char *line, const struct keydef *kd)
 {
-   char *rest;
char *start, *end;
char *res;
unsigned int i;
 
-   rest = skip_columns(line, kd->start_column);
-   for(i = 1; i < kd->start_char && *rest && !isblank(*rest); i++)
-   rest++;
-   start = rest;
+   start = skip_columns(line, kd->start_column);
+   for(i = 1; i < kd->start_char && *start && !isblank(*start); i++)
+   start++;
 
if(kd->end_column) {
-   rest = skip_columns(line, kd->end_column);
+   end = skip_columns(line, kd->end_column);
if(kd->end_char)
-   for(i = 1; i < kd->end_char && *rest && 
!isblank(*rest); i++)
-   rest++;
+   for(i = 1; i < kd->end_char && *end && !isblank(*end); 
i++)
+   end++;
else
-   rest = next_blank(rest);
-   end = rest - 1;
+   end = next_blank(end);
} else {
-   end = rest + strlen(rest);
+   end = line + strlen(line);
}
 
if((res = strndup(start, end - start)) == NULL)




[hackers] [sbase] sort: document -b || Jakob Kramer

2014-05-03 Thread git
commit 814b04e71076abe67af66766b1216ed4974c4c21
Author: Jakob Kramer 
Date:   Sat May 3 20:42:33 2014 +0200

sort: document -b

diff --git a/sort.1 b/sort.1
index 899efe2..7a2057f 100644
--- a/sort.1
+++ b/sort.1
@@ -3,7 +3,7 @@
 sort \- sort lines
 .SH SYNOPSIS
 .B sort
-.RB [ \-nru ]
+.RB [ \-bnru ]
 .RB [ \-k
 .I key
 .R ]...
@@ -14,6 +14,9 @@ writes the sorted concatenation of the given files to stdout. 
 If no file is
 given, sort reads from stdin.
 .SH OPTIONS
 .TP
+.B \-b
+skip leading whitespace of columns when sorting.
+.TP
 .B \-n
 perform a numeric sort.
 .TP
diff --git a/sort.c b/sort.c
index 9ab58d8..0f19b44 100644
--- a/sort.c
+++ b/sort.c
@@ -41,7 +41,7 @@ static bool bflag = false;
 static void
 usage(void)
 {
-   enprintf(2, "usage: %s [-nru] [-k def]... [file...]
", argv0);
+   enprintf(2, "usage: %s [-bnru] [-k def]... [file...]
", argv0);
 }
 
 int




[hackers] [sbase] Support reading checksums from stdin || Daniel Bainton

2014-05-05 Thread git
commit c323f6f2331512003bd53a7da18e1250c2cb5c9c
Author: Daniel Bainton 
Date:   Mon May 5 11:11:37 2014 +0300

Support reading checksums from stdin

diff --git a/md5sum.c b/md5sum.c
index 19babd6..b1d90a6 100644
--- a/md5sum.c
+++ b/md5sum.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include 
 #include 
 #include 
 #include 
@@ -25,16 +26,18 @@ main(int argc, char *argv[])
 {
uint8_t md[MD5_DIGEST_LENGTH];
char *checkfile = NULL;
+   bool cflag = false;
 
ARGBEGIN {
case 'c':
-   checkfile = EARGF(usage());
+   cflag = true;
+   checkfile = ARGF();
break;
default:
usage();
} ARGEND;
 
-   if(checkfile)
+   if(cflag)
return cryptcheck(checkfile, argc, argv, &md5_ops, md, 
sizeof(md));
return cryptmain(argc, argv, &md5_ops, md, sizeof(md));
 }
diff --git a/sha1sum.c b/sha1sum.c
index 68fec73..b497f10 100644
--- a/sha1sum.c
+++ b/sha1sum.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include 
 #include 
 #include 
 #include 
@@ -25,16 +26,18 @@ main(int argc, char *argv[])
 {
uint8_t md[SHA1_DIGEST_LENGTH];
char *checkfile = NULL;
+   bool cflag = false;
 
ARGBEGIN {
case 'c':
-   checkfile = EARGF(usage());
+   cflag = true;
+   checkfile = ARGF();
break;
default:
usage();
} ARGEND;
 
-   if(checkfile)
+   if(cflag)
return cryptcheck(checkfile, argc, argv, &sha1_ops, md, 
sizeof(md));
return cryptmain(argc, argv, &sha1_ops, md, sizeof(md));
 }
diff --git a/sha256sum.c b/sha256sum.c
index 673ab47..d8fefad 100644
--- a/sha256sum.c
+++ b/sha256sum.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include 
 #include 
 #include 
 #include 
@@ -25,16 +26,18 @@ main(int argc, char *argv[])
 {
uint8_t md[SHA256_DIGEST_LENGTH];
char *checkfile = NULL;
+   bool cflag = false;
 
ARGBEGIN {
case 'c':
-   checkfile = EARGF(usage());
+   cflag = true;
+   checkfile = ARGF();
break;
default:
usage();
} ARGEND;
 
-   if(checkfile)
+   if(cflag)
return cryptcheck(checkfile, argc, argv, &sha256_ops, md, 
sizeof(md));
return cryptmain(argc, argv, &sha256_ops, md, sizeof(md));
 }
diff --git a/sha512sum.c b/sha512sum.c
index d7ee473..896515a 100644
--- a/sha512sum.c
+++ b/sha512sum.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include 
 #include 
 #include 
 #include 
@@ -25,16 +26,18 @@ main(int argc, char *argv[])
 {
uint8_t md[SHA512_DIGEST_LENGTH];
char *checkfile = NULL;
+   bool cflag = false;
 
ARGBEGIN {
case 'c':
-   checkfile = EARGF(usage());
+   cflag = true;
+   checkfile = ARGF();
break;
default:
usage();
} ARGEND;
 
-   if(checkfile)
+   if(cflag)
return cryptcheck(checkfile, argc, argv, &sha512_ops, md, 
sizeof(md));
return cryptmain(argc, argv, &sha512_ops, md, sizeof(md));
 }
diff --git a/util/crypt.c b/util/crypt.c
index fffdd55..589104b 100644
--- a/util/crypt.c
+++ b/util/crypt.c
@@ -45,7 +45,9 @@ cryptcheck(char *sumfile, int argc, char *argv[],
int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = EXIT_SUCCESS;
size_t bufsiz = 0;
 
-   if(!(cfp = fopen(sumfile, "r")))
+   if(sumfile == NULL)
+   cfp = stdin;
+   else if(!(cfp = fopen(sumfile, "r")))
eprintf("fopen %s:", sumfile);
 
while(afgets(&line, &bufsiz, cfp)) {
@@ -78,7 +80,8 @@ cryptcheck(char *sumfile, int argc, char *argv[],
}
fclose(fp);
}
-   fclose(cfp);
+   if(sumfile != NULL)
+   fclose(cfp);
free(line);
if(formatsucks > 0) {
weprintf("%d lines are improperly formatted
", formatsucks);




[hackers] [sbase] Add breaks to the sha*sum arg cases || Daniel Bainton

2014-05-05 Thread git
commit 9ad5ca5a1523adb84efcb9d5302bb19e1692d539
Author: Daniel Bainton 
Date:   Mon May 5 11:05:01 2014 +0300

Add breaks to the sha*sum arg cases

diff --git a/sha1sum.c b/sha1sum.c
index 48fe7c5..68fec73 100644
--- a/sha1sum.c
+++ b/sha1sum.c
@@ -29,6 +29,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'c':
checkfile = EARGF(usage());
+   break;
default:
usage();
} ARGEND;
diff --git a/sha256sum.c b/sha256sum.c
index 8f9ed1f..673ab47 100644
--- a/sha256sum.c
+++ b/sha256sum.c
@@ -29,6 +29,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'c':
checkfile = EARGF(usage());
+   break;
default:
usage();
    } ARGEND;
diff --git a/sha512sum.c b/sha512sum.c
index 97ffaca..d7ee473 100644
--- a/sha512sum.c
+++ b/sha512sum.c
@@ -29,6 +29,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'c':
checkfile = EARGF(usage());
+   break;
default:
usage();
} ARGEND;




[hackers] [sbase] Implement cp -f || sin

2014-05-05 Thread git
commit 02918a46e88a521847664bfa91dc09cb91bc6f19
Author: sin 
Date:   Mon May 5 14:58:14 2014 +0100

Implement cp -f

diff --git a/cp.1 b/cp.1
index 0f092c4..9940046 100644
--- a/cp.1
+++ b/cp.1
@@ -17,6 +17,9 @@ copies a given file, naming it the given name.  If multiple 
files are listed
 they will be copied into the given directory.
 .SH OPTIONS
 .TP
+.B \-f
+if an existing destination file cannot be opened, remove it and try again.
+.TP
 .B \-R
 equivalent to -r.
 .TP
diff --git a/cp.c b/cp.c
index fec7aa7..7ae6fac 100644
--- a/cp.c
+++ b/cp.c
@@ -8,7 +8,7 @@
 static void
 usage(void)
 {
-   eprintf("usage: %s [-Rr] source... dest
", argv0);
+   eprintf("usage: %s [-fRr] source... dest
", argv0);
 }
 
 int
@@ -17,6 +17,9 @@ main(int argc, char *argv[])
struct stat st;
 
ARGBEGIN {
+   case 'f':
+   cp_fflag = true;
+   break;
case 'R':
case 'r':
cp_rflag = true;
diff --git a/fs.h b/fs.h
index c034616..6b46434 100644
--- a/fs.h
+++ b/fs.h
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 
+extern bool cp_fflag;
 extern bool cp_rflag;
 extern bool rm_fflag;
 extern bool rm_rflag;
diff --git a/util/cp.c b/util/cp.c
index 9aa637d..471a89b 100644
--- a/util/cp.c
+++ b/util/cp.c
@@ -12,6 +12,7 @@
 #include "../text.h"
 #include "../util.h"
 
+bool cp_fflag = false;
 bool cp_rflag = false;
 
 int
@@ -62,8 +63,12 @@ cp(const char *s1, const char *s2)
if(!(f1 = fopen(s1, "r")))
eprintf("fopen %s:", s1);
 
-   if(!(f2 = fopen(s2, "w")))
-   eprintf("fopen %s:", s2);
+   if(!(f2 = fopen(s2, "w"))) {
+   if (cp_fflag == true)
+   unlink(s2);
+   if (!(f2 = fopen(s2, "w")))
+       eprintf("fopen %s:", s2);
+   }
 
concat(f1, s1, f2, s2);
fchmod(fileno(f2), st.st_mode);
diff --git a/util/fnck.c b/util/fnck.c
index 37da996..84123bc 100644
--- a/util/fnck.c
+++ b/util/fnck.c
@@ -18,4 +18,3 @@ fnck(const char *a, const char *b, int (*fn)(const char *, 
const char *))
if(fn(a, b) == -1)
eprintf("%s -> %s:", a, b);
 }
-




[hackers] [sbase] cp: Don't try to open the file twice in case we did not provide -f || sin

2014-05-05 Thread git
commit b257f7a05f24d218ab37aa43d22e0d19a88bd33b
Author: sin 
Date:   Mon May 5 15:02:16 2014 +0100

cp: Don't try to open the file twice in case we did not provide -f

diff --git a/util/cp.c b/util/cp.c
index 471a89b..33853ad 100644
--- a/util/cp.c
+++ b/util/cp.c
@@ -64,10 +64,13 @@ cp(const char *s1, const char *s2)
eprintf("fopen %s:", s1);
 
if(!(f2 = fopen(s2, "w"))) {
-   if (cp_fflag == true)
+   if (cp_fflag == true) {
unlink(s2);
-   if (!(f2 = fopen(s2, "w")))
+   if (!(f2 = fopen(s2, "w")))
+   eprintf("fopen %s:", s2);
+   } else {
eprintf("fopen %s:", s2);
+   }
}
 
concat(f1, s1, f2, s2);




[hackers] [sbase] Chop one level of indentation || sin

2014-05-05 Thread git
commit 9694305e05c1de0d0f0c903d6fbd6d9c52c78aa5
Author: sin 
Date:   Mon May 5 15:07:55 2014 +0100

Chop one level of indentation

eprintf() will exit the program, no need to use the else construct.

diff --git a/util/cp.c b/util/cp.c
index 33853ad..4e06ddc 100644
--- a/util/cp.c
+++ b/util/cp.c
@@ -28,36 +28,37 @@ cp(const char *s1, const char *s2)
if (stat(s1, &st) == 0 && S_ISDIR(st.st_mode)) {
if (!cp_rflag) {
eprintf("%s: is a directory
", s1);
-   } else {
-   if(!(dp = opendir(s1)))
-   eprintf("opendir %s:", s1);
+   }
 
-   if (mkdir(s2, st.st_mode) == -1 && errno != EEXIST)
-   eprintf("mkdir %s:", s2);
+   if(!(dp = opendir(s1)))
+   eprintf("opendir %s:", s1);
 
-   apathmax(&ns1, &size1);
-   apathmax(&ns2, &size2);
-   while((d = readdir(dp))) {
-   if(strcmp(d->d_name, ".")
-   && strcmp(d->d_name, "..")) {
-   if(snprintf(ns1, size1, "%s/%s", s1,
-   d->d_name) >= size1) {
-   eprintf("%s/%s: filename too 
long
",
-   s1, d->d_name);
-   }
+   if (mkdir(s2, st.st_mode) == -1 && errno != EEXIST)
+   eprintf("mkdir %s:", s2);
 
-   if(snprintf(ns2, size2, "%s/%s", s2,
-   d->d_name) >= size2) {
-   eprintf("%s/%s: filename too 
long
",
-   s2, d->d_name);
-   }
-   fnck(ns1, ns2, cp);
+   apathmax(&ns1, &size1);
+   apathmax(&ns2, &size2);
+   while((d = readdir(dp))) {
+   if(strcmp(d->d_name, ".")
+  && strcmp(d->d_name, "..")) {
+   if(snprintf(ns1, size1, "%s/%s", s1,
+   d->d_name) >= size1) {
+   eprintf("%s/%s: filename too long
",
+   s1, d->d_name);
}
+
+   if(snprintf(ns2, size2, "%s/%s", s2,
+   d->d_name) >= size2) {
+   eprintf("%s/%s: filename too long
",
+   s2, d->d_name);
+   }
+   fnck(ns1, ns2, cp);
}
-   closedir(dp);
-   free(ns1);
-   free(ns2);
}
+
+   closedir(dp);
+   free(ns1);
+   free(ns2);
return 0;
}
if(!(f1 = fopen(s1, "r")))




[hackers] [ubase] str* is in the reserved namespace, rename to replacestr() || sin

2014-05-06 Thread git
commit 5322e83da0f32f1d6805a2c3f492cfd3c178d489
Author: sin 
Date:   Tue May 6 13:36:49 2014 +0100

str* is in the reserved namespace, rename to replacestr()

diff --git a/sysctl.c b/sysctl.c
index a43a333..4aea23c 100644
--- a/sysctl.c
+++ b/sysctl.c
@@ -8,7 +8,7 @@
 #include "util.h"
 
 static void
-streplace(char *s, int a, int b)
+replacestr(char *s, int a, int b)
 {
for (; *s; s++)
if (*s == a)
@@ -25,15 +25,15 @@ getsysctl(char *variable, char **value)
ssize_t n;
size_t sz, i;
 
-   streplace(variable, '.', '/');
+   replacestr(variable, '.', '/');
 
strlcpy(path, "/proc/sys/", sizeof(path));
if (strlcat(path, variable, sizeof(path)) >= sizeof(path)) {
-   streplace(variable, '/', '.');
+   replacestr(variable, '/', '.');
return -1;
}
 
-   streplace(variable, '/', '.');
+   replacestr(variable, '/', '.');
 
fd = open(path, O_RDONLY);
if (fd < 0)
@@ -83,15 +83,15 @@ setsysctl(char *variable, char *value)
int fd;
ssize_t n;
 
-   streplace(variable, '.', '/');
+   replacestr(variable, '.', '/');
 
strlcpy(path, "/proc/sys/", sizeof(path));
if (strlcat(path, variable, sizeof(path)) >= sizeof(path)) {
-   streplace(variable, '/', '.');
+   replacestr(variable, '/', '.');
return -1;
}
 
-   streplace(variable, '/', '.');
+   replacestr(variable, '/', '.');
 
fd = open(path, O_WRONLY);
if (fd < 0)




[hackers] [sbase] sort: ignore trailing newline while sorting || Jakob Kramer

2014-05-06 Thread git
commit 109e8963f5f82641579f72e4367d427db54dae09
Author: Jakob Kramer 
Date:   Tue May 6 13:37:05 2014 +0200

sort: ignore trailing newline while sorting

diff --git a/sort.c b/sort.c
index 1d5f325..26d287d 100644
--- a/sort.c
+++ b/sort.c
@@ -245,7 +245,8 @@ columns(char *line, const struct keydef *kd)
else
end = end_column(end);
} else {
-   end = line + strlen(line);
+   if((end = strchr(line, '
')) == NULL)
+   end = strchr(line, '



[hackers] [sbase] renice(1): renice is not PASTE || Jakob Kramer

2014-05-06 Thread git
commit 8a44c352eee6493df07d6792cdcd5513aa7758cb
Author: Jakob Kramer 
Date:   Tue May 6 16:13:22 2014 +0200

renice(1): renice is not PASTE

diff --git a/renice.1 b/renice.1
index bce23f5..d9d928d 100644
--- a/renice.1
+++ b/renice.1
@@ -1,4 +1,4 @@
-.TH PASTE 1 renice-VERSION "Jun 2013"
+.TH RENICE 1 renice-VERSION "Jun 2013"
 .SH NAME
 renice \- set nice values of running processes
 .SH "SYNOPSIS"




[hackers] [sbase] sort: work with signed integers as well || Jakob Kramer

2014-05-06 Thread git
commit 0723c8d32eabcb326381235e4aed265ee93af7b4
Author: Jakob Kramer 
Date:   Tue May 6 13:35:06 2014 +0200

sort: work with signed integers as well

diff --git a/sort.c b/sort.c
index 0f19b44..1d5f325 100644
--- a/sort.c
+++ b/sort.c
@@ -9,10 +9,10 @@
 #include "util.h"
 
 struct keydef {
-   unsigned start_column;
-   unsigned end_column;
-   unsigned start_char;
-   unsigned end_char;
+   int start_column;
+   int end_column;
+   int start_char;
+   int end_char;
 };
 
 struct kdlist {
@@ -146,7 +146,7 @@ linecmp(const char **a, const char **b)
else if(!(node == head) && !node->next)
res = strcmp(s1, s2);
else if(nflag)
-   res = strtoul(s1, 0, 10) - strtoul(s2, 0, 10);
+   res = strtol(s1, 0, 10) - strtol(s2, 0, 10);
else
res = strcmp(s1, s2);
 
@@ -167,17 +167,22 @@ parse_keydef(struct keydef *kd, char *s)
kd->end_column = 0;
kd->end_char = 0;
 
-   kd->start_column = strtoul(rest, &rest, 10);
-   if(!kd->start_column)
-   enprintf(2, "starting column cannot be 0
");
+   kd->start_column = strtol(rest, &rest, 10);
+   if(kd->start_column < 1)
+   return -1;
if(*rest == '.')
-   kd->start_char = strtoul(rest+1, &rest, 10);
+   kd->start_char = strtol(rest+1, &rest, 10);
+   if(kd->start_char < 1)
+   return -1;
if(*rest == ',') {
-   kd->end_column = strtoul(rest+1, &rest, 10);
+   kd->end_column = strtol(rest+1, &rest, 10);
if(kd->end_column && kd->end_column < kd->start_column)
-   enprintf(2, ",%u is too small
", kd->end_column);
-   if(*rest == '.')
-   kd->end_char = strtoul(rest+1, &rest, 10);
+   return -1;
+   if(*rest == '.') {
+   kd->end_char = strtol(rest+1, &rest, 10);
+   if(kd->end_char < 1)
+   return -1;
+   }
}
if(*rest != '



[hackers] [sbase] sort: add support for "per-keydef" flags || Jakob Kramer

2014-05-06 Thread git
commit 6f7e9a5078614306bfd01c08fc4cf81fa25d2114
Author: Jakob Kramer 
Date:   Tue May 6 16:07:05 2014 +0200

sort: add support for "per-keydef" flags

diff --git a/sort.1 b/sort.1
index 7a2057f..955cebd 100644
--- a/sort.1
+++ b/sort.1
@@ -1,4 +1,4 @@
-.TH NL 1 sbase\-VERSION
+.TH SORT 1 sbase\-VERSION
 .SH NAME
 sort \- sort lines
 .SH SYNOPSIS
@@ -27,15 +27,26 @@ reverses the sort.
 prints equal lines only once.
 .TP
 .B \-k key
-specifies a key definition of the form BSR[.BsR][,BER[.BeR]],
+specifies a key definition of the form
+.BR S [. s ][ f ][, E [. e ][ f ]]
 where
-.B S,
-.B s,
-.B E,
+.BR S ,
+.BR s ,
+.BR E ,
 and
 .B e
 are the starting column, starting character in that column, ending column and
 the ending character of that column respectively.  If they are not specified,
-s refers to the first character of the specified starting column, E refers to
-the last column of every line, and e refers to the last character of that last
-column.
+.B s
+refers to the first character of the specified starting column,
+.B E
+refers to the last column of every line, and
+.B e
+refers to the last character of that last column.
+.B f
+can be used to specify options
+.RB ( n ,
+.BR b )
+that only apply to this key definition.
+.B b
+is special in that it only applies to the column that it was specified after.
diff --git a/sort.c b/sort.c
index 26d287d..203490b 100644
--- a/sort.c
+++ b/sort.c
@@ -13,6 +13,14 @@ struct keydef {
int end_column;
int start_char;
int end_char;
+   int flags;
+};
+
+enum {
+   MOD_N  = 1 << 1,
+   MOD_STARTB = 1 << 2,
+   MOD_ENDB   = 1 << 3,
+   MOD_R  = 1 << 4
 };
 
 struct kdlist {
@@ -23,20 +31,18 @@ struct kdlist {
 static struct kdlist *head = NULL;
 static struct kdlist *curr = NULL;
 
-static void addkeydef(char *);
+static void addkeydef(char *, int);
 static void freelist(void);
 static int linecmp(const char **, const char **);
 static char *next_nonblank(char *);
 static char *next_blank(char *);
-static int parse_keydef(struct keydef *, char *);
-static char *skip_columns(char *, size_t);
+static int parse_flags(char **, int *, int);
+static int parse_keydef(struct keydef *, char *, int);
+static char *skip_columns(char *, size_t, bool);
 static char *end_column(char *);
 static char *columns(char *, const struct keydef *);
 
-static bool rflag = false;
 static bool uflag = false;
-static bool nflag = false;
-static bool bflag = false;
 
 static void
 usage(void)
@@ -50,28 +56,31 @@ main(int argc, char *argv[])
long i;
FILE *fp;
struct linebuf linebuf = EMPTY_LINEBUF;
+   int global_flags = 0;
 
ARGBEGIN {
case 'n':
-   nflag = true;
+   global_flags |= MOD_N;
break;
case 'r':
-   rflag = true;
+   global_flags |= MOD_R;
break;
case 'u':
uflag = true;
break;
case 'b':
-   bflag = true;
+   global_flags |= MOD_STARTB | MOD_ENDB;
break;
case 'k':
-   addkeydef(EARGF(usage()));
+   addkeydef(EARGF(usage()), global_flags);
break;
default:
usage();
} ARGEND;
 
-   addkeydef("1");
+   if(!head && global_flags)
+   addkeydef("1", global_flags);
+   addkeydef("1", global_flags & MOD_R);
 
if(argc == 0) {
getlines(stdin, &linebuf);
@@ -98,7 +107,7 @@ main(int argc, char *argv[])
 }
 
 static void
-addkeydef(char *def)
+addkeydef(char *def, int flags)
 {
struct kdlist *node;
 
@@ -107,7 +116,7 @@ addkeydef(char *def)
enprintf(2, "malloc:");
if(!head)
head = node;
-   if(parse_keydef(&node->keydef, def))
+   if(parse_keydef(&node->keydef, def, flags))
enprintf(2, "faulty key definition
");
if(curr)
curr->next = node;
@@ -145,19 +154,42 @@ linecmp(const char **a, const char **b)
res = 0;
else if(!(node == head) && !node->next)
res = strcmp(s1, s2);
-   else if(nflag)
+   else if(node->keydef.flags & MOD_N)
res = strtol(s1, 0, 10) - strtol(s2, 0, 10);
else
res = strcmp(s1, s2);
 
+   if(node->keydef.flags & MOD_R)
+   res = -res;
+
free(s1);
free(s2);
}
-   return rflag ? -res : res;
+   return res;
 }
 
 static int
-parse_keydef(struct keydef *kd, char *s)
+parse_flags(char **s, int *flags, int bflag)
+{
+   while(isalpha(**s))
+  

[hackers] [sbase] sort: simplify linecmp, rename curr => tail || Jakob Kramer

2014-05-06 Thread git
commit 9366f48b1fc5fcb2971334189e43b6050cc1e58c
Author: Jakob Kramer 
Date:   Tue May 6 18:47:02 2014 +0200

sort: simplify linecmp, rename curr => tail

diff --git a/sort.c b/sort.c
index 203490b..a00e902 100644
--- a/sort.c
+++ b/sort.c
@@ -29,7 +29,7 @@ struct kdlist {
 };
 
 static struct kdlist *head = NULL;
-static struct kdlist *curr = NULL;
+static struct kdlist *tail = NULL;
 
 static void addkeydef(char *, int);
 static void freelist(void);
@@ -118,10 +118,10 @@ addkeydef(char *def, int flags)
head = node;
if(parse_keydef(&node->keydef, def, flags))
enprintf(2, "faulty key definition
");
-   if(curr)
-   curr->next = node;
+   if(tail)
+   tail->next = node;
node->next = NULL;
-   curr = node;
+   tail = node;
 }
 
 static void
@@ -147,13 +147,10 @@ linecmp(const char **a, const char **b)
s1 = columns((char *)*a, &node->keydef);
s2 = columns((char *)*b, &node->keydef);
 
-   /* don't consider modifiers if it's the default key
-* definition that was implicitly added */
-   /* if -u is given, don't use default */
-   if(uflag && !(node == head) && !node->next)
+   /* if -u is given, don't use default key definition
+* unless it is the only one */
+   if(uflag && node == tail && head != tail)
res = 0;
-   else if(!(node == head) && !node->next)
-   res = strcmp(s1, s2);
else if(node->keydef.flags & MOD_N)
res = strtol(s1, 0, 10) - strtol(s2, 0, 10);
else




[hackers] [st] Also clears ESC_START on interrupt characters during sequences. || Colona

2014-05-08 Thread git
commit 5e917ab2874de556de12ce43e9a97300c9c722a2
Author: Colona 
Date:   Wed May 7 10:05:27 2014 +0200

Also clears ESC_START on interrupt characters during sequences.

Otherwise, the rest of the input is interpreted as a new escape
sequence.
For the ESC character, ESC_START is re-set in tcontrolcode.

diff --git a/st.c b/st.c
index fe44608..baab589 100644
--- a/st.c
+++ b/st.c
@@ -2446,7 +2446,7 @@ tputc(char *c, int len) {
   (ascii == '' || ascii == 030 ||
ascii == 032  || ascii == 033 ||
ISCONTROLC1(unicodep))) {
-   term.esc &= ~ESC_STR;
+   term.esc &= ~(ESC_START|ESC_STR);
term.esc |= ESC_STR_END;
} else if(strescseq.len + len < sizeof(strescseq.buf) - 1) {
memmove(&strescseq.buf[strescseq.len], c, len);




[hackers] [st] End a sequence only on CAN, SUB,  and C1s. || Colona

2014-05-09 Thread git
commit e31829f659a818e438bf2fe45708abb2983f8765
Author: Colona 
Date:   Fri May 9 10:23:53 2014 +0200

End a sequence only on CAN, SUB,  and C1s.

diff --git a/st.c b/st.c
index baab589..fd872c1 100644
--- a/st.c
+++ b/st.c
@@ -2335,19 +2335,19 @@ tcontrolcode(uchar ascii) {
switch(ascii) {
case '  ':   /* HT */
tputtab(1);
-   break;
+   return;
case '':   /* BS */
tmoveto(term.c.x-1, term.c.y);
-   break;
+   return;
case '
':   /* CR */
tmoveto(0, term.c.y);
-   break;
+   return;
case '':   /* LF */
case '':   /* VT */
case '
':   /* LF */
/* go to first col if the mode is set */
tnewline(IS_SET(MODE_CRLF));
-   break;
+   return;
case '':   /* BEL */
if(term.esc & ESC_STR_END) {
/* backwards compatibility to xterm */
@@ -2366,10 +2366,10 @@ tcontrolcode(uchar ascii) {
return;
case '': /* SO */
term.charset = 0;
-   break;
+   return;
case '': /* SI */
term.charset = 1;
-   break;
+   return;
case '': /* SUB */
tsetchar(question, &term.c.attr, term.c.x, term.c.y);
case '': /* CAN */
@@ -2380,6 +2380,7 @@ tcontrolcode(uchar ascii) {
case '': /* XON (IGNORED) */
case '': /* XOFF (IGNORED) */
case 0177:   /* DEL (IGNORED) */
+   return;
case 0x84:   /* TODO: IND */
case 0x85:   /* TODO: NEL */
case 0x88:   /* TODO: HTS */
@@ -2396,6 +2397,7 @@ tcontrolcode(uchar ascii) {
case 0x9f:   /* TODO: APC */
break;
}
+   /* only CAN, SUB,  and C1 chars interrupt a sequence */
term.esc &= ~(ESC_STR_END|ESC_STR);
return;
 }




[hackers] [st] Redraw needs all dirty lines to have flash etc. work. || Christoph Lohmann

2014-05-09 Thread git
commit bdb850a16a6d7a2d12b2bd5500a3b7d70290a74a
Author: Christoph Lohmann <2...@r-36.net>
Date:   Fri May 9 17:12:58 2014 +0200

Redraw needs all dirty lines to have flash etc. work.

diff --git a/st.c b/st.c
index fd872c1..5946c7c 100644
--- a/st.c
+++ b/st.c
@@ -3439,6 +3439,7 @@ void
 redraw(int timeout) {
struct timespec tv = {0, timeout * 1000};
 
+   tfulldirt();
draw();
 
if(timeout > 0) {




[hackers] [sbase] Switching to real name || FRIGN

2014-05-11 Thread git
commit 8ea17b2a7d5807572d98412a466369056a37da9a
Author: FRIGN 
Date:   Sun May 11 10:56:18 2014 +0200

Switching to real name

diff --git a/LICENSE b/LICENSE
index 3de9279..d46b353 100644
--- a/LICENSE
+++ b/LICENSE
@@ -24,7 +24,7 @@ MIT/X Consortium License
 © 2013 Christian Hesse 
 © 2013 Markus Wichmann 
 © 2014 Silvan Jegen 
-© 2014 FRIGN 
+© 2014 Laslo Hunhold 
 © 2014 Daniel Bainton 
 
 Permission is hereby granted, free of charge, to any person obtaining a




[hackers] [sbase] Make grep more memory-efficient || FRIGN

2014-05-11 Thread git
commit fb1bfe24bb4ae08bdd56732244a74d89033dd130
Author: FRIGN 
Date:   Mon May 12 00:31:07 2014 +0200

Make grep more memory-efficient

diff --git a/grep.c b/grep.c
index 269ec92..f6bbcc1 100644
--- a/grep.c
+++ b/grep.c
@@ -11,7 +11,7 @@
 enum { Match = 0, NoMatch = 1, Error = 2 };
 
 static void addpattern(const char *);
-static bool grep(FILE *, const char *);
+static bool grep(FILE *, const char *, int);
 
 static bool eflag = false;
 static bool vflag = false;
@@ -20,7 +20,6 @@ static char mode = 0;
 
 static struct plist {
char *pattern;
-   regex_t preg;
struct plist *next;
 } *phead;
 
@@ -35,7 +34,7 @@ main(int argc, char *argv[])
 {
bool match = false;
struct plist *pnode, *tmp;
-   int i, n, flags = REG_NOSUB;
+   int i, flags = REG_NOSUB;
FILE *fp;
 
ARGBEGIN {
@@ -62,8 +61,9 @@ main(int argc, char *argv[])
usage();
} ARGEND;
 
+   /* no pattern */
if(argc == 0 && !eflag)
-   usage(); /* no pattern */
+   usage();
 
/* If -e is not specified treat it as if it were */
if(!eflag) {
@@ -72,23 +72,14 @@ main(int argc, char *argv[])
argv++;
}
 
-   /* Compile regex for all search patterns */
-   for(pnode = phead; pnode; pnode = pnode->next) {
-   if((n = regcomp(&pnode->preg, pnode->pattern, flags)) != 0) {
-   char buf[BUFSIZ];
-
-   regerror(n, &pnode->preg, buf, sizeof buf);
-   enprintf(Error, "invalid pattern: %s
", buf);
-   }
-   }
many = (argc > 1);
if(argc == 0) {
-   match = grep(stdin, "");
+   match = grep(stdin, "", flags);
} else {
for(i = 0; i < argc; i++) {
if(!(fp = fopen(argv[i], "r")))
enprintf(Error, "fopen %s:", argv[i]);
-   if(grep(fp, argv[i]))
+   if(grep(fp, argv[i], flags))
match = true;
fclose(fp);
}
@@ -96,7 +87,6 @@ main(int argc, char *argv[])
pnode = phead;
while(pnode) {
tmp = pnode->next;
-   regfree(&pnode->preg);
free(pnode->pattern);
free(pnode);
pnode = tmp;
@@ -120,20 +110,30 @@ addpattern(const char *pattern)
 }
 
 bool
-grep(FILE *fp, const char *str)
+grep(FILE *fp, const char *str, int flags)
 {
char *buf = NULL;
long n, c = 0;
+   int r;
+   static regex_t preg;
size_t size = 0, len;
struct plist *pnode;
bool match = false;
 
for(n = 1; afgets(&buf, &size, fp); n++) {
for(pnode = phead; pnode; pnode = pnode->next) {
+   if((r = regcomp(&preg, pnode->pattern, flags)) != 0) {
+   char err[BUFSIZ];
+
+   regerror(r, &preg, err, sizeof err);
+   enprintf(Error, "invalid pattern: %s
", err);
+   }
if(buf[(len = strlen(buf))-1] == '
')
buf[--len] = '



[hackers] [sbase] Declare error buffer at start of block || sin

2014-05-11 Thread git
commit 11eef783fe81a36a8887683f56436697152c6372
Author: sin 
Date:   Mon May 12 00:39:56 2014 +0100

Declare error buffer at start of block

diff --git a/grep.c b/grep.c
index f6bbcc1..8651619 100644
--- a/grep.c
+++ b/grep.c
@@ -112,6 +112,7 @@ addpattern(const char *pattern)
 bool
 grep(FILE *fp, const char *str, int flags)
 {
+   char err[BUFSIZ];
char *buf = NULL;
long n, c = 0;
int r;
@@ -123,8 +124,6 @@ grep(FILE *fp, const char *str, int flags)
for(n = 1; afgets(&buf, &size, fp); n++) {
for(pnode = phead; pnode; pnode = pnode->next) {
if((r = regcomp(&preg, pnode->pattern, flags)) != 0) {
-   char err[BUFSIZ];
-
regerror(r, &preg, err, sizeof err);
enprintf(Error, "invalid pattern: %s
", err);
}




[hackers] [sbase] build warnings: initialise values... || Hiltjo Posthuma

2014-05-12 Thread git
commit 5b3a0a9382e41c1129e1fc64ebdd877eb7179952
Author: Hiltjo Posthuma 
Date:   Mon May 12 11:01:47 2014 +

build warnings: initialise values...

... to make fix gcc warnings with -Wall.

Signed-off-by: Hiltjo Posthuma 

diff --git a/split.c b/split.c
index c91865e..638af54 100644
--- a/split.c
+++ b/split.c
@@ -27,9 +27,9 @@ main(int argc, char *argv[])
char *prefix = "x";
char *file = NULL;
char *tmp, *end;
-   uint64_t size = 1000, scale, n;
+   uint64_t size = 1000, scale = 1, n;
int always = 0;
-   FILE *in=stdin, *out=NULL;
+   FILE *in = stdin, *out = NULL;
 
ARGBEGIN {
case 'b':
diff --git a/xargs.c b/xargs.c
index ada00b6..c80c524 100644
--- a/xargs.c
+++ b/xargs.c
@@ -40,9 +40,9 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-   int leftover;
+   int leftover = 0;
long argsz, argmaxsz;
-   char *arg;
+   char *arg = "";
int i, a;
 
ARGBEGIN {
@@ -67,7 +67,6 @@ main(int argc, char *argv[])
/* Leave some room for environment variables */
argmaxsz -= 4 * 1024;
 
-   leftover = 0;
do {
argsz = 0; i = 0; a = 0;
if (argc > 0) {




[hackers] [sbase] Revert "Make grep more memory-efficient" || sin

2014-05-12 Thread git
commit 4896bdf6de4abc90f2c6a073f065683910d5d15a
Author: sin 
Date:   Mon May 12 11:59:39 2014 +0100

Revert "Make grep more memory-efficient"

This reverts commit d9a098ae6bc07188cbaefcd188e5911dec41815d.

Conflicts:
grep.c

Hiltjo Posthuma  said:

(Re)compiling the regex for each line doesn't make sense (imho) and
slows it down a lot.

A simple test:

time seq 1 1 | grep 'a'

sbase grep (before patch):
0m22.21s real 0m0.00s user 0m0.00s system

sbase grep (after patch):
2m16.28s real 0m0.00s user 0m0.00s system

coreutils grep:
0m1.15s real 0m0.00s user 0m0.00s system

So the patch should be reverted I think.

diff --git a/grep.c b/grep.c
index 8651619..f4fe7df 100644
--- a/grep.c
+++ b/grep.c
@@ -11,7 +11,7 @@
 enum { Match = 0, NoMatch = 1, Error = 2 };
 
 static void addpattern(const char *);
-static bool grep(FILE *, const char *, int);
+static bool grep(FILE *, const char *);
 
 static bool eflag = false;
 static bool vflag = false;
@@ -20,6 +20,7 @@ static char mode = 0;
 
 static struct plist {
char *pattern;
+   regex_t preg;
struct plist *next;
 } *phead;
 
@@ -34,7 +35,7 @@ main(int argc, char *argv[])
 {
bool match = false;
struct plist *pnode, *tmp;
-   int i, flags = REG_NOSUB;
+   int i, n, flags = REG_NOSUB;
FILE *fp;
 
ARGBEGIN {
@@ -61,9 +62,8 @@ main(int argc, char *argv[])
usage();
} ARGEND;
 
-   /* no pattern */
if(argc == 0 && !eflag)
-   usage();
+   usage(); /* no pattern */
 
/* If -e is not specified treat it as if it were */
if(!eflag) {
@@ -72,14 +72,23 @@ main(int argc, char *argv[])
argv++;
}
 
+   /* Compile regex for all search patterns */
+   for(pnode = phead; pnode; pnode = pnode->next) {
+   if((n = regcomp(&pnode->preg, pnode->pattern, flags)) != 0) {
+   char buf[BUFSIZ];
+
+   regerror(n, &pnode->preg, buf, sizeof buf);
+   enprintf(Error, "invalid pattern: %s
", buf);
+   }
+   }
many = (argc > 1);
if(argc == 0) {
-   match = grep(stdin, "", flags);
+   match = grep(stdin, "");
} else {
for(i = 0; i < argc; i++) {
if(!(fp = fopen(argv[i], "r")))
enprintf(Error, "fopen %s:", argv[i]);
-   if(grep(fp, argv[i], flags))
+   if(grep(fp, argv[i]))
match = true;
fclose(fp);
}
@@ -87,6 +96,7 @@ main(int argc, char *argv[])
pnode = phead;
while(pnode) {
tmp = pnode->next;
+   regfree(&pnode->preg);
free(pnode->pattern);
free(pnode);
pnode = tmp;
@@ -110,29 +120,20 @@ addpattern(const char *pattern)
 }
 
 bool
-grep(FILE *fp, const char *str, int flags)
+grep(FILE *fp, const char *str)
 {
-   char err[BUFSIZ];
char *buf = NULL;
long n, c = 0;
-   int r;
-   static regex_t preg;
size_t size = 0, len;
struct plist *pnode;
bool match = false;
 
for(n = 1; afgets(&buf, &size, fp); n++) {
for(pnode = phead; pnode; pnode = pnode->next) {
-   if((r = regcomp(&preg, pnode->pattern, flags)) != 0) {
-   regerror(r, &preg, err, sizeof err);
-   enprintf(Error, "invalid pattern: %s
", err);
-   }
if(buf[(len = strlen(buf))-1] == '
')
buf[--len] = '



[hackers] [st] Allow mouse selection override using ShiftMask || Hiltjo Posthuma

2014-05-15 Thread git
commit cf890e5bf06a65a35fe195aa1ef8ae3e1eb55f51
Author: Hiltjo Posthuma 
Date:   Mon May 12 14:39:37 2014 +0200

Allow mouse selection override using ShiftMask

Similar to xterm or urxvt holding shift before selecting text with the mouse
allows to override copying text. For example in tmux with "mode-mouse on" or
vim (compiled with --with-x), mc, htop, etc.

forceselmod in config.h sets the modifier to use this mode, by default
ShiftMask.

Signed-off-by: Hiltjo Posthuma 

diff --git a/config.def.h b/config.def.h
index 646a88a..6e2be9a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -154,6 +154,11 @@ static KeySym mappedkeys[] = { -1 };
  */
 static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
 
+/* Override mouse-select while mask is active (when MODE_MOUSE is set).
+ * Note that if you want to use ShiftMask with selmasks, set this to an other
+ * modifier, set to 0 to not use it. */
+static uint forceselmod = ShiftMask;
+
 static Key key[] = {
/* keysym   maskstring  appkey appcursor crlf */
{ XK_KP_Home,   ShiftMask,  "",   0,   -1,0},
@@ -357,7 +362,6 @@ static Key key[] = {
  * ButtonRelease and MotionNotify.
  * If no match is found, regular selection is used.
  */
-
 static uint selmasks[] = {
[SEL_RECTANGULAR] = Mod1Mask,
 };
diff --git a/st.c b/st.c
index 5946c7c..78d8a01 100644
--- a/st.c
+++ b/st.c
@@ -765,7 +765,7 @@ selsnap(int mode, int *x, int *y, int direction) {
 void
 getbuttoninfo(XEvent *e) {
int type;
-   uint state = e->xbutton.state &~Button1Mask;
+   uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
 
sel.alt = IS_SET(MODE_ALTSCREEN);
 
@@ -858,7 +858,7 @@ bpress(XEvent *e) {
struct timeval now;
Mousekey *mk;
 
-   if(IS_SET(MODE_MOUSE)) {
+   if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
mousereport(e);
return;
}
@@ -1090,7 +1090,7 @@ xsetsel(char *str) {
 
 void
 brelease(XEvent *e) {
-   if(IS_SET(MODE_MOUSE)) {
+   if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
mousereport(e);
return;
}
@@ -1113,7 +1113,7 @@ void
 bmotion(XEvent *e) {
int oldey, oldex, oldsby, oldsey;
 
-   if(IS_SET(MODE_MOUSE)) {
+   if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
mousereport(e);
return;
}




[hackers] [surf] Add information about the dmenu requirement. || Christoph Lohmann

2014-05-17 Thread git
commit 285cc3843fef1c44fff395221beb67f9f82b783f
Author: Christoph Lohmann <2...@r-36.net>
Date:   Sat May 17 19:24:25 2014 +0200

Add information about the dmenu requirement.

Thanks !

diff --git a/README b/README
index c87b69b..da4577f 100644
--- a/README
+++ b/README
@@ -6,6 +6,7 @@ Requirements
 
 In order to build surf you need GTK+ and Webkit/GTK+ header files.
 
+In order to use the functionality of the url-bar, also install dmenu[0].
 
 Installation
 
@@ -26,7 +27,7 @@ See the manpage for further options.
 
 Running surf in tabbed
 --
-For running surf in tabbed[0] there is a script included in the distribution,
+For running surf in tabbed[1] there is a script included in the distribution,
 which is run like this:
 
surf-open.sh [URI]
@@ -34,5 +35,6 @@ which is run like this:
 Further invocations of the script will run surf with the specified URI in this
 instance of tabbed.
 
-[0] http://tools.suckless.org/tabbed
+[0] http://tools.suckless.org/dmenu
+[1] http://tools.suckless.org/tabbed
 
diff --git a/surf.1 b/surf.1
index 1530ec6..2b7080c 100644
--- a/surf.1
+++ b/surf.1
@@ -157,7 +157,7 @@ Go to next search result.
 Go to previous search result.
 .TP
 .B Ctrl\-g
-Opens the URL-bar.
+Opens the URL-bar (requires dmenu installed).
 .TP
 .B Ctrl\-p
 Loads URI from primary selection.




[hackers] [tabbed] add urgent color cmdline options || Markus Teich

2014-05-19 Thread git
commit c778de59e30fd65556209623aec5f8544a3e0e2f
Author: Markus Teich 
Date:   Wed May 14 01:50:10 2014 +0200

add urgent color cmdline options

Signed-off-by: Christoph Lohmann <2...@r-36.net>

diff --git a/tabbed.1 b/tabbed.1
index 177eacd..83af311 100644
--- a/tabbed.1
+++ b/tabbed.1
@@ -14,14 +14,18 @@ tabbed \- generic tabbed interface
 .IR name ]
 .RB [ \-p
 .IR [ s +/- ] pos ]
+.RB [ \-o
+.IR normbgcol ]
+.RB [ \-O
+.IR normfgcol ]
 .RB [ \-t
 .IR selbgcol ]
 .RB [ \-T
 .IR selfgcol ]
 .RB [ \-u
-.IR normbgcol ]
+.IR urgbgcol ]
 .RB [ \-U
-.IR normfgcol ]
+.IR urgfgcol ]
 .RB [ \-r
 .IR narg ]
 .IR [ command ... ]
@@ -78,20 +82,26 @@ with the window id, rather than appending it to the end.
 .B \-s
 will disable automatic spawning of the command.
 .TP
-.BI \-t " selbgcol"
-defines the selected background color.
+.BI \-o " normbgcol"
+defines the normal background color.
 .IR #RGB ,
 .IR #RRGGBB ,
 and X color names are supported.
 .TP
+.BI \-O " normfgcol"
+defines the normal foreground color.
+.TP
+.BI \-t " selbgcol"
+defines the selected background color.
+.TP
 .BI \-T " selfgbcol"
 defines the selected foreground color.
 .TP
-.BI \-u " normbgcol"
-defines the normal background color.
+.BI \-u " urgbgcol"
+defines the urgent background color.
 .TP
-.BI \-U " normfgcol"
-defines the normal foreground color.
+.BI \-U " urgfgbcol"
+defines the urgent foreground color.
 .TP
 .B \-v
 prints version information to stderr, then exits.
diff --git a/tabbed.c b/tabbed.c
index d2900f2..2341998 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -1218,7 +1218,8 @@ char *argv0;
 void
 usage(void) {
die("usage: %s [-dfhsv] [-g geometry] [-n name] [-p [s+/-]pos] [-r 
narg] "
-   "[-u color] [-U color] [-t color] [-T color] command...
", argv0);
+   "[-o color] [-O color] [-t color] [-T color] [-u color] [-U 
color] "
+   "command...
", argv0);
 }
 
 int
@@ -1259,6 +1260,12 @@ main(int argc, char *argv[]) {
case 's':
doinitspawn = False;
break;
+   case 'o':
+   normbgcolor = EARGF(usage());
+   break;
+   case 'O':
+   normfgcolor = EARGF(usage());
+   break;
case 't':
selbgcolor = EARGF(usage());
break;
@@ -1266,10 +1273,10 @@ main(int argc, char *argv[]) {
selfgcolor = EARGF(usage());
break;
case 'u':
-   normbgcolor = EARGF(usage());
+   urgbgcolor = EARGF(usage());
break;
case 'U':
-   normfgcolor = EARGF(usage());
+   urgfgcolor = EARGF(usage());
break;
case 'v':
die("tabbed-"VERSION", © 2009-2014"




[hackers] [st] Fixing trailing whitespaces. || Christoph Lohmann

2014-05-24 Thread git
commit f4ebb3180f9f03bc35034348a5aff8745eac9ebf
Author: Christoph Lohmann <2...@r-36.net>
Date:   Sat May 24 13:48:44 2014 +0200

Fixing trailing whitespaces.

diff --git a/st.c b/st.c
index a6b4ada..6424b54 100644
--- a/st.c
+++ b/st.c
@@ -2742,7 +2742,7 @@ xloadcols(void) {
if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, 
&dc.col[i]))
die("Could not allocate color %d
", i);
}
-   
+
/* load colours [232-255] ; grayscale */
for(; i < 256; i++) {
color.red = color.green = color.blue = 0x0808 + 0x0a0a * 
(i-(6*6*6+16));
@@ -3143,12 +3143,12 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, 
int bytelen) {
 
if(base.mode & ATTR_BOLD) {
/*
-* change basic system colours [0-7] 
+* change basic system colours [0-7]
 * to bright system colours [8-15]
 */
if(BETWEEN(base.fg, 0, 7))
fg = &dc.col[base.fg + 8];
-   
+
font = &dc.bfont;
frcflags = FRC_BOLD;
}




[hackers] [st] Brightening is again on the TODO list. || Christoph Lohmann

2014-05-24 Thread git
commit 488977c8efd0b3ad5bcc7a76f35e737f56381f45
Author: Christoph Lohmann <2...@r-36.net>
Date:   Sat May 24 13:52:24 2014 +0200

Brightening is again on the TODO list.

diff --git a/TODO b/TODO
index 3866f64..00cfdac 100644
--- a/TODO
+++ b/TODO
@@ -12,6 +12,7 @@ drawing
 ---
 * add diacritics support to xdraws()
 * make the font cache simpler
+* add better support for brightening of the upper colors
 
 bugs
 




[hackers] [st] Fix some more LICENSE changes. || Christoph Lohmann

2014-05-24 Thread git
commit d03aa8d20bcc8a94a7737331a9ec0bf11df3e572
Author: Christoph Lohmann <2...@r-36.net>
Date:   Sat May 24 21:27:54 2014 +0200

Fix some more LICENSE changes.

diff --git a/LICENSE b/LICENSE
index 64dc414..0180b49 100644
--- a/LICENSE
+++ b/LICENSE
@@ -2,14 +2,14 @@ MIT/X Consortium License
 
 © 2009-2012 Aurélien APTEL 
 © 2009 Anselm R Garbe 
-© 2012 Roberto E. Vargas Caballero 
-© 2012 Christoph Lohmann <20h at r-36 dot net>
+© 2012-2014 Roberto E. Vargas Caballero 
+© 2012-2014 Christoph Lohmann <20h at r-36 dot net>
 © 2013 Eon S. Jeon 
 © 2013 Alexander Sedov 
 © 2013 Mark Edgar 
 © 2013 Eric Pruitt 
 © 2013 Michael Forney 
-© 2013 Markus Teich 
+© 2013-2014 Markus Teich 
 © 2014 Laslo Hunhold 
 
 Permission is hereby granted, free of charge, to any person obtaining a




[hackers] [st] Fixed copying empty lines inside selection. || Alexander

2014-05-26 Thread git
commit 2411308bd24c4db97a3bb06d38f183a679aec1ea
Author: Alexander 
Date:   Mon May 26 09:23:56 2014 +0400

Fixed copying empty lines inside selection.

The code was assuming that empty lines have implicit wrap-around attribute.

Signed-off-by: Roberto E. Vargas Caballero 

diff --git a/st.c b/st.c
index 6424b54..506be0f 100644
--- a/st.c
+++ b/st.c
@@ -949,7 +949,7 @@ getsel(void) {
 * st.
 * FIXME: Fix the computer world.
 */
-   if(y < sel.ne.y && x > 0 && !((gp-1)->mode & ATTR_WRAP))
+   if(y < sel.ne.y && !(x > 0 && (gp-1)->mode & ATTR_WRAP))
*ptr++ = '
';
 
/*




[hackers] [sbase] Proper copyright header for strlcpy and strlcat || sin

2014-05-28 Thread git
commit 69cde2370329a5e4e6c17e7ed3322519ff256ab3
Author: sin 
Date:   Wed May 28 11:11:35 2014 +0100

Proper copyright header for strlcpy and strlcat

diff --git a/util/strlcat.c b/util/strlcat.c
index 14bea97..5631195 100644
--- a/util/strlcat.c
+++ b/util/strlcat.c
@@ -1,4 +1,19 @@
-/* Taken from OpenBSD */
+/*
+ * Copyright (c) 1998 Todd C. Miller 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
 #include 
 #include 
 #include "../util.h"
diff --git a/util/strlcpy.c b/util/strlcpy.c
index 62fb7f6..5a4051a 100644
--- a/util/strlcpy.c
+++ b/util/strlcpy.c
@@ -1,4 +1,19 @@
-/* Taken from OpenBSD */
+/*
+ * Copyright (c) 1998 Todd C. Miller 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
 #include 
 #include 
 #include "../util.h"




[hackers] [dwm] updated copyright notice in LICENSE file || Anselm R Garbe

2014-05-29 Thread git
commit b468873b2b71d351ed7b5a4c75f62060999c46eb
Author: Anselm R Garbe 
Date:   Thu May 29 18:02:12 2014 +0200

updated copyright notice in LICENSE file

diff --git a/LICENSE b/LICENSE
index 2e53d0a..dc2326a 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 MIT/X Consortium License
 
-© 2006-2012 Anselm R Garbe 
+© 2006-2014 Anselm R Garbe 
 © 2007-2011 Peter Hartlich 
 © 2010-2011 Connor Lane Smith 
 © 2006-2009 Jukka Salmi 




[hackers] [dmenu] updated copyright notices in LICENSE and dmenu.c file || Anselm R Garbe

2014-05-29 Thread git
commit 4c50e43df46e486a0fac632d34eaed37359ceba7
Author: Anselm R Garbe 
Date:   Thu May 29 18:03:53 2014 +0200

updated copyright notices in LICENSE and dmenu.c file

diff --git a/LICENSE b/LICENSE
index 0df62c6..39c4b6e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 MIT/X Consortium License
 
-© 2006-2013 Anselm R Garbe 
+© 2006-2014 Anselm R Garbe 
 © 2010-2012 Connor Lane Smith 
 © 2009 Gottox 
 © 2009 Markus Schnalke 
diff --git a/dmenu.c b/dmenu.c
index 8d9bbb6..dd2c128 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -69,7 +69,7 @@ main(int argc, char *argv[]) {
for(i = 1; i < argc; i++)
/* these options take no arguments */
if(!strcmp(argv[i], "-v")) {  /* prints version information 
*/
-   puts("dmenu-"VERSION", © 2006-2012 dmenu engineers, see 
LICENSE for details");
+   puts("dmenu-"VERSION", © 2006-2014 dmenu engineers, see 
LICENSE for details");
exit(EXIT_SUCCESS);
}
else if(!strcmp(argv[i], "-b"))   /* appears at the bottom of 
the screen */




[hackers] [dwm] same as before with dwm.c as well || Anselm R Garbe

2014-05-29 Thread git
commit 18248ebf4b9465b837e717dcd14a5202a98248e0
Author: Anselm R Garbe 
Date:   Thu May 29 18:05:17 2014 +0200

same as before with dwm.c as well

diff --git a/dwm.c b/dwm.c
index 1bbb4b3..ffc8864 100644
--- a/dwm.c
+++ b/dwm.c
@@ -2046,7 +2046,7 @@ zoom(const Arg *arg) {
 int
 main(int argc, char *argv[]) {
if(argc == 2 && !strcmp("-v", argv[1]))
-   die("dwm-"VERSION", © 2006-2012 dwm engineers, see LICENSE for 
details
");
+   die("dwm-"VERSION", © 2006-2014 dwm engineers, see LICENSE for 
details
");
else if(argc != 1)
die("usage: dwm [-v]
");
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())




[hackers] [sbase] Use -std=c99 by default || sin

2014-05-31 Thread git
commit 07dd658f0d04c42015c3f102cbeeb17d16bedd65
Author: sin 
Date:   Sat May 31 17:55:25 2014 +0100

Use -std=c99 by default

Note, the code is largely c89 clean.  This is to avoid certain
warnings on some systems (OSX).

diff --git a/config.mk b/config.mk
index 078cf5e..2967eed 100644
--- a/config.mk
+++ b/config.mk
@@ -9,7 +9,7 @@ MANPREFIX = $(PREFIX)/share/man
 #CC = musl-gcc
 LD = $(CC)
 CPPFLAGS = -D_BSD_SOURCE -D_GNU_SOURCE
-CFLAGS   = -g -ansi -Wall -Wno-long-long -pedantic $(CPPFLAGS)
+CFLAGS   = -g -std=c99 -Wall -pedantic $(CPPFLAGS)
 LDFLAGS  = -g
 
 #CC = tcc




[hackers] [st] Fixing italic bold. || Christoph Lohmann

2014-06-01 Thread git
commit ede83bd08b922f2f53264876f6500b564d3c5ef0
Author: Christoph Lohmann <2...@r-36.net>
Date:   Sun Jun 1 15:54:28 2014 +0200

Fixing italic bold.

Thanks Felipe Spychalski  for the patch!

diff --git a/st.c b/st.c
index 506be0f..f48dab4 100644
--- a/st.c
+++ b/st.c
@@ -3149,8 +3149,13 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, 
int bytelen) {
if(BETWEEN(base.fg, 0, 7))
fg = &dc.col[base.fg + 8];
 
-   font = &dc.bfont;
-   frcflags = FRC_BOLD;
+   if(base.mode & ATTR_ITALIC) {
+   font = &dc.ibfont;
+   frcflags = FRC_ITALICBOLD;
+   } else {
+   font = &dc.bfont;
+   frcflags = FRC_BOLD;
+   }
}
 
if(IS_SET(MODE_REVERSE)) {




[hackers] [st] Don't report release events for mouse wheel || Balazs Kezes

2014-06-01 Thread git
commit ba36d1394b3add5b9d4c174f1443cc312bcc7e09
Author: Balazs Kezes 
Date:   Sat May 31 22:24:58 2014 +0100

Don't report release events for mouse wheel

Signed-off-by: Christoph Lohmann <2...@r-36.net>

diff --git a/st.c b/st.c
index f48dab4..79a4e0a 100644
--- a/st.c
+++ b/st.c
@@ -829,6 +829,8 @@ mousereport(XEvent *e) {
/* MODE_MOUSEX10: no button release reporting */
if(IS_SET(MODE_MOUSEX10))
return;
+   if (button == 64 || button == 65)
+   return;
}
}
 




[hackers] [tabbed] Replace emallocz with ecalloc. || noname

2014-06-01 Thread git
commit 9d1d6d9409df1a7045806c1e802d89d08b0ae0a7
Author: noname 
Date:   Sat May 24 23:09:56 2014 +0400

Replace emallocz with ecalloc.

Signed-off-by: Christoph Lohmann <2...@r-36.net>

diff --git a/tabbed.c b/tabbed.c
index 2341998..ba22f9a 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -97,7 +97,7 @@ static void destroynotify(const XEvent *e);
 static void die(const char *errstr, ...);
 static void drawbar(void);
 static void drawtext(const char *text, unsigned long col[ColLast]);
-static void *emallocz(size_t size);
+static void *ecalloc(size_t n, size_t size);
 static void *erealloc(void *o, size_t size);
 static void expose(const XEvent *e);
 static void focus(int c);
@@ -399,11 +399,11 @@ drawtext(const char *text, unsigned long col[ColLast]) {
 }
 
 void *
-emallocz(size_t size) {
+ecalloc(size_t n, size_t size) {
void *p;
 
-   if(!(p = calloc(1, size)))
-   die("tabbed: cannot malloc
");
+   if(!(p = calloc(n, size)))
+   die("tabbed: cannot calloc
");
return p;
 }
 
@@ -713,7 +713,7 @@ manage(Window w) {
}
}
 
-   c = emallocz(sizeof(*c));
+   c = ecalloc(1, sizeof *c);
c->win = w;
 
nclients++;
@@ -921,7 +921,7 @@ void
 setcmd(int argc, char *argv[], int replace) {
int i;
 
-   cmd = emallocz((argc+3) * sizeof(*cmd));
+   cmd = ecalloc(argc + 3, sizeof *cmd);
if (argc == 0)
return;
for(i = 0; i < argc; i++)




[hackers] [st] Fixing color and refactor xsetcolorname. || Christoph Lohmann

2014-06-01 Thread git
commit c6fcb78b3a9a73b691875048848430c18870a0fc
Author: Christoph Lohmann <2...@r-36.net>
Date:   Sun Jun 1 17:08:16 2014 +0200

Fixing color and refactor xsetcolorname.

By  the recommendation of FRIGN I refactored xsetcolorname to remove the
unnecessary r, g, b variables when allocating a new  color.  Colors  are
now freed and set to the new color. A die() should not happen here. Oth‐
erwise it is easy for applications to kill st. St should be resilent  to
malicious input.

Second  this  patch  standardises  the  naming  of  »color«. There is no
»colour« here. Maybe in some parts of the world.

diff --git a/st.c b/st.c
index 79a4e0a..11d01df 100644
--- a/st.c
+++ b/st.c
@@ -179,8 +179,8 @@ typedef unsigned long ulong;
 typedef unsigned short ushort;
 
 typedef XftDraw *Draw;
-typedef XftColor Colour;
-typedef Colormap Colourmap;
+typedef XftColor Color;
+typedef Colormap Colormap;
 
 typedef struct {
char c[UTF_SIZ]; /* character code */
@@ -241,7 +241,7 @@ typedef struct {
 /* Purely graphic info */
 typedef struct {
Display *dpy;
-   Colourmap cmap;
+   Colormap cmap;
Window win;
Drawable buf;
Atom xembed, wmdeletewin, netwmname, netwmpid;
@@ -340,7 +340,7 @@ typedef struct {
 
 /* Drawing Context */
 typedef struct {
-   Colour col[MAX(LEN(colorname), 256)];
+   Color col[MAX(LEN(colorname), 256)];
Font font, bfont, ifont, ibfont;
GC gc;
 } DC;
@@ -1631,7 +1631,7 @@ tdefcolor(int *attr, int *npar, int l) {
uint r, g, b;
 
switch (attr[*npar + 1]) {
-   case 2: /* direct colour in RGB space */
+   case 2: /* direct color in RGB space */
if (*npar + 4 >= l) {
fprintf(stderr,
"erresc(38): Incorrect number of parameters (%d)
",
@@ -1648,7 +1648,7 @@ tdefcolor(int *attr, int *npar, int l) {
else
idx = TRUECOLOR(r, g, b);
break;
-   case 5: /* indexed colour */
+   case 5: /* indexed color */
if (*npar + 2 >= l) {
fprintf(stderr,
"erresc(38): Incorrect number of parameters (%d)
",
@@ -1663,8 +1663,8 @@ tdefcolor(int *attr, int *npar, int l) {
break;
case 0: /* implemented defined (only foreground) */
case 1: /* transparent */
-   case 3: /* direct colour in CMY space */
-   case 4: /* direct colour in CMYK space */
+   case 3: /* direct color in CMY space */
+   case 4: /* direct color in CMYK space */
default:
fprintf(stderr,
"erresc(38): gfx attr %d unknown
", attr[*npar]);
@@ -2151,7 +2151,7 @@ strhandle(void) {
/* FALLTHROUGH */
case 104: /* color reset, here p = NULL */
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
-   if (!xsetcolorname(j, p)) {
+   if(xsetcolorname(j, p)) {
fprintf(stderr, "erresc: invalid color %s
", p);
} else {
/*
@@ -2720,14 +2720,14 @@ xloadcols(void) {
int i;
XRenderColor color = { .alpha = 0x };
static bool loaded;
-   Colour *cp;
+   Color *cp;
 
if(loaded) {
for (cp = dc.col; cp < dc.col + LEN(dc.col); ++cp)
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
}
 
-   /* load colours [0-15] and [256-LEN(colorname)] (config.h) */
+   /* load colors [0-15] and [256-LEN(colorname)] (config.h) */
for(i = 0; i < LEN(colorname); i++) {
if(!colorname[i])
continue;
@@ -2736,7 +2736,7 @@ xloadcols(void) {
}
}
 
-   /* load colours [16-231] ; same colours as xterm */
+   /* load colors [16-231] ; same colors as xterm */
for(i = 16; i < 6*6*6+16; i++) {
color.red   = sixd_to_16bit( ((i-16)/36)%6 );
color.green = sixd_to_16bit( ((i-16)/6) %6 );
@@ -2745,7 +2745,7 @@ xloadcols(void) {
die("Could not allocate color %d
", i);
}
 
-   /* load colours [232-255] ; grayscale */
+   /* load colors [232-255] ; grayscale */
for(; i < 256; i++) {
color.red = color.green = color.blue = 0x0808 + 0x0a0a * 
(i-(6*6*6+16));
if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, 
&dc.col[i]))
@@ -2757,33 +2757,45 @@ xloadcols(void) {
 int
 xsetcolorname(int x, const char *name) {
XRenderColor color = { .alpha = 0x };
-   Colour colour;
+   Color ncolor;
+
if(!BETWEEN(x, 0, LEN(colorname)))
-   return -1;
+   return 1;
+
if(!name) {
-   if(BE

[hackers] [sbase] strlcat, strlcpy style || Hiltjo Posthuma

2014-06-01 Thread git
commit 2dbb69493249468aa9c9359cc5eb66c49239fd3c
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 13:35:58 2014 +0200

strlcat, strlcpy style

Signed-off-by: Hiltjo Posthuma 

diff --git a/util/strlcat.c b/util/strlcat.c
index 5631195..c64b1c7 100644
--- a/util/strlcat.c
+++ b/util/strlcat.c
@@ -20,32 +20,32 @@
 
 /*
  * Appends src to string dst of size siz (unlike strncat, siz is the
- * full size of dst, not space left).  At most siz-1 characters
- * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
  * Returns strlen(src) + MIN(siz, strlen(initial dst)).
  * If retval >= siz, truncation occurred.
  */
 size_t
 strlcat(char *dst, const char *src, size_t siz)
 {
-char *d = dst;
-const char *s = src;
-size_t n = siz;
-size_t dlen;
-/* Find the end of dst and adjust bytes left but don't go past end */
-while (n-- != 0 && *d != '



[hackers] [sbase] cut, uudecode: free buf after use || Hiltjo Posthuma

2014-06-01 Thread git
commit daad071b31a94ac86d5dd501211fde8e6984e48c
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 13:49:07 2014 +0200

cut, uudecode: free buf after use

Signed-off-by: Hiltjo Posthuma 

diff --git a/cut.c b/cut.c
index b058301..d21fcbe 100644
--- a/cut.c
+++ b/cut.c
@@ -96,8 +96,8 @@ seek(const char *s, size_t pos, size_t *prev, size_t count)
 static void
 cut(FILE *fp)
 {
-   static char *buf = NULL;
-   static size_t size = 0;
+   char *buf = NULL;
+   size_t size = 0;
char *s;
size_t i, n, p;
Range *r;
@@ -123,6 +123,7 @@ cut(FILE *fp)
}
putchar('
');
}
+   free(buf);
 }
 
 int
diff --git a/uudecode.c b/uudecode.c
index 9a40964..1196661 100644
--- a/uudecode.c
+++ b/uudecode.c
@@ -173,4 +173,5 @@ uudecode(FILE *fp, FILE *outfp)
afgets(&bufb, &n, fp);
if (strnlen(bufb, 3) < 3 || strncmp(bufb, "end", 3) != 0 || bufb[3] != '
')
eprintf("invalid uudecode footer \"end\" not found
");
+   free(bufb);
 }




[hackers] [sbase] add agetline, separate estrtod to util || Hiltjo Posthuma

2014-06-01 Thread git
commit d12e953f18e9746c83d4bed532fa2c51cc3c5d48
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 13:57:22 2014 +0200

add agetline, separate estrtod to util

Signed-off-by: Hiltjo Posthuma 

diff --git a/Makefile b/Makefile
index ad1e43b..abfceab 100644
--- a/Makefile
+++ b/Makefile
@@ -7,12 +7,14 @@ HDR = crypt.h fs.h text.h md5.h sha1.h sha256.h sha512.h 
util.h arg.h
 LIB = \
util/afgets.o\
util/agetcwd.o   \
+   util/agetline.o  \
util/apathmax.o  \
util/concat.o\
util/cp.o\
util/crypt.o \
util/enmasse.o   \
util/eprintf.o   \
+   util/estrtod.o   \
util/estrtol.o   \
util/fnck.o  \
util/getlines.o  \
diff --git a/seq.c b/seq.c
index 5b3d5f0..9beb568 100644
--- a/seq.c
+++ b/seq.c
@@ -8,7 +8,6 @@
 
 static int digitsleft(const char *);
 static int digitsright(const char *);
-static double estrtod(const char *);
 static bool validfmt(const char *);
 
 static void
@@ -75,7 +74,7 @@ main(int argc, char *argv[])
left = MAX(digitsleft(starts), digitsleft(ends));
 
snprintf(ftmp, sizeof ftmp, "%%0%d.%df",
-   right+left+(right != 0), right);
+   right + left + (right != 0), right);
} else
snprintf(ftmp, sizeof ftmp, "%%.%df", right);
}
@@ -89,7 +88,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
 }
 
-int
+static int
 digitsleft(const char *d)
 {
char *exp;
@@ -100,10 +99,10 @@ digitsleft(const char *d)
exp = strpbrk(d, "eE");
shift = exp ? estrtol(&exp[1], 10) : 0;
 
-   return MAX(0, strspn(d, "-0123456789")+shift);
+   return MAX(0, strspn(d, "-0123456789") + shift);
 }
 
-int
+static int
 digitsright(const char *d)
 {
char *exp;
@@ -113,22 +112,10 @@ digitsright(const char *d)
shift = exp ? estrtol(&exp[1], 10) : 0;
after = (d = strchr(d, '.')) ? strspn(&d[1], "0123456789") : 0;
 
-   return MAX(0, after-shift);
+   return MAX(0, after - shift);
 }
 
-double
-estrtod(const char *s)
-{
-   char *end;
-   double d;
-
-   d = strtod(s, &end);
-   if(end == s || *end != '



[hackers] [sbase] grep: improvements || Hiltjo Posthuma

2014-06-01 Thread git
commit 97fb4a1f9cf68f78da3838723086515072525408
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 14:03:10 2014 +0200

grep: improvements

improvements:
- improve statuscode behaviour
  - don't exit if a file in a series fails. exit 2 if an error occured
in a file series. don't exit if there is a read error (like: grep
 input file is a directory).
- use agetline instead of agets().

with the simple test: time seq 1 1 | grep 'a'
its 12 seconds (from 24 seconds) on my machine.

Signed-off-by: Hiltjo Posthuma 

diff --git a/grep.c b/grep.c
index f4fe7df..715f864 100644
--- a/grep.c
+++ b/grep.c
@@ -11,7 +11,7 @@
 enum { Match = 0, NoMatch = 1, Error = 2 };
 
 static void addpattern(const char *);
-static bool grep(FILE *, const char *);
+static int grep(FILE *, const char *);
 
 static bool eflag = false;
 static bool vflag = false;
@@ -33,9 +33,9 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-   bool match = false;
struct plist *pnode, *tmp;
-   int i, n, flags = REG_NOSUB;
+   int i, n, m, flags = REG_NOSUB, match = NoMatch;
+   char buf[BUFSIZ];
FILE *fp;
 
ARGBEGIN {
@@ -75,8 +75,6 @@ main(int argc, char *argv[])
/* Compile regex for all search patterns */
for(pnode = phead; pnode; pnode = pnode->next) {
if((n = regcomp(&pnode->preg, pnode->pattern, flags)) != 0) {
-   char buf[BUFSIZ];
-
regerror(n, &pnode->preg, buf, sizeof buf);
enprintf(Error, "invalid pattern: %s
", buf);
}
@@ -86,10 +84,14 @@ main(int argc, char *argv[])
match = grep(stdin, "");
} else {
for(i = 0; i < argc; i++) {
-   if(!(fp = fopen(argv[i], "r")))
-   enprintf(Error, "fopen %s:", argv[i]);
-   if(grep(fp, argv[i]))
-   match = true;
+   if(!(fp = fopen(argv[i], "r"))) {
+   weprintf("fopen %s:", argv[i]);
+   match = Error;
+   continue;
+   }
+   m = grep(fp, argv[i]);
+   if(m == Error || (match != Error && m == Match))
+   match = m;
fclose(fp);
}
}
@@ -101,37 +103,33 @@ main(int argc, char *argv[])
free(pnode);
pnode = tmp;
}
-   return match ? Match : NoMatch;
+   return match;
 }
 
-void
+static void
 addpattern(const char *pattern)
 {
struct plist *pnode;
 
-   pnode = malloc(sizeof(*pnode));
-   if(!pnode)
+   if(!(pnode = malloc(sizeof(*pnode
eprintf("malloc:");
-   pnode->pattern = strdup(pattern);
-   if(!pnode->pattern)
+   if(!(pnode->pattern = strdup(pattern)))
eprintf("strdup:");
pnode->next = phead;
phead = pnode;
 }
 
-bool
+static int
 grep(FILE *fp, const char *str)
 {
char *buf = NULL;
-   long n, c = 0;
-   size_t size = 0, len;
+   size_t len = 0, size = 0;
+   long c = 0, n;
struct plist *pnode;
-   bool match = false;
+   int match = NoMatch;
 
-   for(n = 1; afgets(&buf, &size, fp); n++) {
+   for(n = 1; (len = agetline(&buf, &size, fp)) != -1; n++) {
for(pnode = phead; pnode; pnode = pnode->next) {
-   if(buf[(len = strlen(buf))-1] == '
')
-   buf[--len] = '



[hackers] [sbase] cut: improvements || Hiltjo Posthuma

2014-06-01 Thread git
commit 97ca7c8b6df0c90e600cbbd258b74bd524d78aef
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 14:39:34 2014 +0200

cut: improvements

- use agetline().
- code style.
- free allocated list.
- don't close stdin if "-" is given.

diff --git a/cut.c b/cut.c
index d21fcbe..64081f9 100644
--- a/cut.c
+++ b/cut.c
@@ -31,19 +31,23 @@ insert(Range *r)
Range *l, *p, *t;
 
for(p = NULL, l = list; l; p = l, l = l->next) {
-   if(r->max && r->max+1 < l->min) {
+   if(r->max && r->max + 1 < l->min) {
r->next = l;
break;
-   } else if(!l->max || r->min < l->max+2) {
+   } else if(!l->max || r->min < l->max + 2) {
l->min = MIN(r->min, l->min);
for(p = l, t = l->next; t; p = t, t = t->next)
-   if(r->max && r->max+1 < t->min) break;
+   if(r->max && r->max + 1 < t->min)
+   break;
l->max = (p->max && r->max) ? MAX(p->max, r->max) : 0;
l->next = t;
return;
}
}
-   if(p) p->next = r; else list = r;
+   if(p)
+   p->next = r;
+   else
+   list = r;
 }
 
 static void
@@ -54,8 +58,10 @@ parselist(char *str)
Range *r;
 
for(s = str; *s; s++) {
-   if(*s == ' ') *s = ',';
-   if(*s == ',') n++;
+   if(*s == ' ')
+   *s = ',';
+   if(*s == ',')
+   n++;
}
if(!(r = malloc(n * sizeof(Range
eprintf("malloc:");
@@ -69,6 +75,18 @@ parselist(char *str)
}
 }
 
+static void
+freelist(void) {
+   Range *l = list, *next;
+
+   while(l) {
+   next = l->next;
+   free(l);
+   l->next = NULL;
+   l = next;
+   }
+}
+
 static size_t
 seek(const char *s, size_t pos, size_t *prev, size_t count)
 {
@@ -79,15 +97,18 @@ seek(const char *s, size_t pos, size_t *prev, size_t count)
if((t = memchr(s, 0, n)))
return t - s;
if(nflag)
-   while(n && !UTF8_POINT(s[n])) n--;
+   while(n && !UTF8_POINT(s[n]))
+   n--;
*prev += n;
return n;
} else if(mode == 'c') {
for(n++, t = s; *t; t++)
-   if(UTF8_POINT(*t) && !--n) break;
+   if(UTF8_POINT(*t) && !--n)
+   break;
} else {
-   for(t = (count < 2) ? s : s+1; n && *t; t++)
-   if(*t == delim && !--n && count) break;
+   for(t = (count < 2) ? s : s + 1; n && *t; t++)
+   if(*t == delim && !--n && count)
+   break;
}
*prev = pos;
return t - s;
@@ -96,15 +117,14 @@ seek(const char *s, size_t pos, size_t *prev, size_t count)
 static void
 cut(FILE *fp)
 {
-   char *buf = NULL;
-   size_t size = 0;
-   char *s;
-   size_t i, n, p;
+   char *buf = NULL, *s;
+   size_t size = 0, i, n, p;
+   ssize_t len;
Range *r;
 
-   while(afgets(&buf, &size, fp)) {
-   if(buf[i = strlen(buf)-1] == '
')
-   buf[i] = 0;
+   while((len = agetline(&buf, &size, fp)) != -1) {
+   if(len && buf[len - 1] == '
')
+   buf[len - 1] = '



[hackers] [sbase] code style || Hiltjo Posthuma

2014-06-01 Thread git
commit 953ebf35730c986ca68b0cf7d97f22dceccb08a0
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 14:59:47 2014 +0200

code style

Signed-off-by: Hiltjo Posthuma 

diff --git a/basename.c b/basename.c
index e3d1a14..f5f681c 100644
--- a/basename.c
+++ b/basename.c
@@ -39,4 +39,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/cal.c b/cal.c
index c1ff8da..7fca626 100644
--- a/cal.c
+++ b/cal.c
@@ -189,4 +189,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/chroot.c b/chroot.c
index 2b88937..e0a1577 100644
--- a/chroot.c
+++ b/chroot.c
@@ -46,4 +46,3 @@ main(int argc, char *argv[])
_exit(savederrno == ENOENT ? 127 : 126);
return EXIT_FAILURE;
 }
-
diff --git a/cksum.c b/cksum.c
index bb2c322..a252f93 100644
--- a/cksum.c
+++ b/cksum.c
@@ -93,7 +93,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
 }
 
-void
+static void
 cksum(FILE *fp, const char *s)
 {
unsigned char buf[BUFSIZ];
@@ -117,4 +117,3 @@ cksum(FILE *fp, const char *s)
printf(" %s", s);
putchar('
');
 }
-
diff --git a/comm.c b/comm.c
index 694d48c..fe3323b 100644
--- a/comm.c
+++ b/comm.c
@@ -66,7 +66,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
 }
 
-void
+static void
 printline(int pos, char *line)
 {
int i;
@@ -81,7 +81,7 @@ printline(int pos, char *line)
printf("%s", line);
 }
 
-char *
+static char *
 nextline(char *buf, int n, FILE *f, char *name)
 {
buf = fgets(buf, n, f);
@@ -93,7 +93,7 @@ nextline(char *buf, int n, FILE *f, char *name)
return buf;
 }
 
-void
+static void
 finish(int pos, FILE *f, char *name)
 {
char buf[LINE_MAX+1];
@@ -103,4 +103,3 @@ finish(int pos, FILE *f, char *name)
 
exit(EXIT_FAILURE);
 }
-
diff --git a/date.c b/date.c
index 2a798e5..0c0041c 100644
--- a/date.c
+++ b/date.c
@@ -43,4 +43,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/dirname.c b/dirname.c
index 1c4297f..50820c6 100644
--- a/dirname.c
+++ b/dirname.c
@@ -26,4 +26,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/echo.c b/echo.c
index 41ff4bb..fb7e3dd 100644
--- a/echo.c
+++ b/echo.c
@@ -31,4 +31,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/env.c b/env.c
index f82c178..70fdfb1 100644
--- a/env.c
+++ b/env.c
@@ -34,7 +34,7 @@ main(int argc, char *argv[])
 
if(*argv) {
execvp(*argv, argv);
-   enprintf(127-(errno!=EEXIST), "env: '%s':", *argv);
+   enprintf(127 - (errno != EEXIST), "env: '%s':", *argv);
}
 
while(environ && *environ)
@@ -42,4 +42,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/fold.c b/fold.c
index 6a95124..84888e5 100644
--- a/fold.c
+++ b/fold.c
@@ -58,7 +58,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
 }
 
-void
+static void
 fold(FILE *fp, long width)
 {
char *buf = NULL;
@@ -69,7 +69,7 @@ fold(FILE *fp, long width)
free(buf);
 }
 
-void
+static void
 foldline(const char *str, long width)
 {
bool space;
diff --git a/head.c b/head.c
index 2903f49..93fd818 100644
--- a/head.c
+++ b/head.c
@@ -46,7 +46,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
 }
 
-void
+static void
 head(FILE *fp, const char *str, long n)
 {
char buf[BUFSIZ];
diff --git a/kill.c b/kill.c
index 70e95f9..ea9a777 100644
--- a/kill.c
+++ b/kill.c
@@ -76,4 +76,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/ln.c b/ln.c
index c0bd8f3..029bce5 100644
--- a/ln.c
+++ b/ln.c
@@ -41,4 +41,3 @@ main(int argc, char *argv[])
 
return EXIT_SUCCESS;
 }
-
diff --git a/ls.c b/ls.c
index 5d98c92..88ae3c0 100644
--- a/ls.c
+++ b/ls.c
@@ -96,7 +96,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
 }
 
-int
+static int
 entcmp(const void *va, const void *vb)
 {
const Entry *a = va, *b = vb;
@@ -107,7 +107,7 @@ entcmp(const void *va, const void *vb)
return strcmp(a->name, b->name);
 }
 
-void
+static void
 ls(Entry *ent)
 {
if(S_ISDIR(ent->mode) && !dflag) {
@@ -117,7 +117,7 @@ ls(Entry *ent)
}
 }
 
-void
+static void
 lsdir(const char *path)
 {
char *cwd, *p;
@@ -169,7 +169,7 @@ lsdir(const char *path)
free(cwd);
 }
 
-void
+static void
 mkent(Entry *ent, char *path, bool dostat)
 {
struct stat st;
@@ -188,7 +188,7 @@ mkent(Entry *ent, char *path, bool dostat)
ent->ino= st.st_ino;
 }
 
-char *
+static char *
 indicator(mode_t mode)
 {
if(!Fflag)
@@ -210,7 +210,7 @@ indicator(mode_t mode)
return "";
 }
 
-void
+static void
 output(Entry *ent)
 {
    char buf[BUFSIZ], *fmt;
@@ -290,4 +290,3 @@ output(Entry *ent)
}
putchar('
');
 }

[hackers] [sbase] check snprintf error aswell, handle as truncation error || Hiltjo Posthuma

2014-06-01 Thread git
commit eac0f658cfce9aa70492127fbc980aca9b0f8f7b
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 15:01:09 2014 +0200

check snprintf error aswell, handle as truncation error

Signed-off-by: Hiltjo Posthuma 

diff --git a/du.c b/du.c
index 304fee1..8382178 100644
--- a/du.c
+++ b/du.c
@@ -120,6 +120,7 @@ du(const char *path)
struct dirent *dent;
struct stat st;
long n = 0, m;
+   int r;
 
if (lstat(path, &st) < 0)
eprintf("stat: %s:", path);
@@ -149,8 +150,9 @@ du(const char *path)
n += m;
if (aflag && !sflag) {
if (S_ISLNK(st.st_mode)) {
-   if (snprintf(file, sizeof(file), "%s/%s",
-cwd, dent->d_name) >= sizeof(file))
+   r = snprintf(file, sizeof(file), "%s/%s",
+cwd, dent->d_name);
+   if(r >= sizeof(file) || r < 0)
eprintf("path too long
");
} else {
    xrealpath(dent->d_name, file);
diff --git a/mktemp.c b/mktemp.c
index cf2572f..e001dac 100644
--- a/mktemp.c
+++ b/mktemp.c
@@ -21,7 +21,7 @@ main(int argc, char *argv[])
char *template = "tmp.XX";
char *tmpdir = "/tmp", *p;
char tmppath[PATH_MAX];
-   int fd;
+   int fd, r;
 
ARGBEGIN {
case 'd':
@@ -42,8 +42,9 @@ main(int argc, char *argv[])
if ((p = getenv("TMPDIR")))
tmpdir = p;
 
-   if (snprintf(tmppath, sizeof(tmppath),
-"%s/%s", tmpdir, template) >= sizeof(tmppath))
+   r = snprintf(tmppath, sizeof(tmppath),
+"%s/%s", tmpdir, template);
+   if (r >= sizeof(tmppath) || r < 0)
eprintf("path too long
");
if (dflag) {
if (!mkdtemp(tmppath)) {
diff --git a/util/cp.c b/util/cp.c
index e8627cd..753e616 100644
--- a/util/cp.c
+++ b/util/cp.c
@@ -24,6 +24,7 @@ cp(const char *s1, const char *s2)
struct dirent *d;
struct stat st;
DIR *dp;
+   int r;
 
if (stat(s1, &st) == 0 && S_ISDIR(st.st_mode)) {
if (!cp_rflag)
@@ -40,14 +41,13 @@ cp(const char *s1, const char *s2)
while((d = readdir(dp))) {
if(strcmp(d->d_name, ".")
   && strcmp(d->d_name, "..")) {
-   if(snprintf(ns1, size1, "%s/%s", s1,
-   d->d_name) >= size1) {
+   r = snprintf(ns1, size1, "%s/%s", s1, 
d->d_name);
+   if(r >= size1 || r < 0) {
eprintf("%s/%s: filename too long
",
s1, d->d_name);
}
-
-   if(snprintf(ns2, size2, "%s/%s", s2,
-   d->d_name) >= size2) {
+   r = snprintf(ns2, size2, "%s/%s", s2, 
d->d_name);
+   if(r >= size2 || r < 0) {
eprintf("%s/%s: filename too long
",
s2, d->d_name);
}




[hackers] [sbase] remove afgets || Hiltjo Posthuma

2014-06-01 Thread git
commit 2ab2d2ee3b4c67dec4de2c0d436ab40d80f4624e
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 15:12:33 2014 +0200

remove afgets

Signed-off-by: Hiltjo Posthuma 

diff --git a/Makefile b/Makefile
index abfceab..27a6693 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,6 @@ include config.mk
 
 HDR = crypt.h fs.h text.h md5.h sha1.h sha256.h sha512.h util.h arg.h
 LIB = \
-   util/afgets.o\
util/agetcwd.o   \
util/agetline.o  \
util/apathmax.o  \
diff --git a/text.h b/text.h
index afcfbe7..f2e582e 100644
--- a/text.h
+++ b/text.h
@@ -8,6 +8,5 @@ struct linebuf {
 #define EMPTY_LINEBUF {NULL, 0, 0,}
 void getlines(FILE *, struct linebuf *);
 
-char *afgets(char **, size_t *, FILE *);
 ssize_t agetline(char **, size_t *, FILE *);
 void concat(FILE *, const char *, FILE *, const char *);
diff --git a/util/afgets.c b/util/afgets.c
deleted file mode 100644
index 4b4ffe2..000
--- a/util/afgets.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include 
-#include 
-#include 
-
-#include "../text.h"
-#include "../util.h"
-
-char *
-afgets(char **p, size_t *size, FILE *fp)
-{
-   char buf[BUFSIZ];
-   size_t n, len = 0;
-
-   while(fgets(buf, sizeof buf, fp)) {
-   len += (n = strlen(buf));
-   if(len+1 > *size && !(*p = realloc(*p, len+1)))
-   eprintf("realloc:");
-
-   memcpy(&(*p)[len-n], buf, n);
-   (*p)[len] = '



[hackers] [sbase] use agetline instead of agets || Hiltjo Posthuma

2014-06-01 Thread git
commit fab4b384e7eb22613174f8adee6510ea3b78db6b
Author: Hiltjo Posthuma 
Date:   Sun Jun 1 15:04:32 2014 +0200

use agetline instead of agets

also use agetline where fgets with a static buffer was used previously.

Signed-off-by: Hiltjo Posthuma 

diff --git a/fold.c b/fold.c
index 84888e5..c307bb9 100644
--- a/fold.c
+++ b/fold.c
@@ -64,7 +64,7 @@ fold(FILE *fp, long width)
char *buf = NULL;
size_t size = 0;
 
-   while(afgets(&buf, &size, fp))
+   while(agetline(&buf, &size, fp) != -1)
foldline(buf, width);
free(buf);
 }
diff --git a/head.c b/head.c
index 93fd818..8313648 100644
--- a/head.c
+++ b/head.c
@@ -3,6 +3,7 @@
 #include 
 #include 
 #include 
+#include "text.h"
 #include "util.h"
 
 static void head(FILE *, const char *, long);
@@ -49,14 +50,17 @@ main(int argc, char *argv[])
 static void
 head(FILE *fp, const char *str, long n)
 {
-   char buf[BUFSIZ];
-   long i = 0;
+   char *buf = NULL;
+   size_t size = 0;
+   ssize_t len;
+   unsigned long i = 0;
 
-   while(i < n && fgets(buf, sizeof buf, fp)) {
+   while(i < n && ((len = agetline(&buf, &size, fp)) != -1)) {
fputs(buf, stdout);
-   if(buf[strlen(buf)-1] == '
')
+   if(buf[len - 1] == '
')
i++;
}
+   free(buf);
if(ferror(fp))
eprintf("%s: read error:", str);
 }
diff --git a/nl.c b/nl.c
index 4e2df70..2d15391 100644
--- a/nl.c
+++ b/nl.c
@@ -68,7 +68,7 @@ nl(FILE *fp)
long n = 0;
size_t size = 0;
 
-   while(afgets(&buf, &size, fp)) {
+   while(agetline(&buf, &size, fp) != -1) {
if((mode == 'a')
   || (mode == 'p'
   && !regexec(&preg, buf, 0, NULL, 0))
diff --git a/tail.c b/tail.c
index c02fc41..59e68ca 100644
--- a/tail.c
+++ b/tail.c
@@ -55,25 +55,28 @@ main(int argc, char *argv[])
 static void
 dropinit(FILE *fp, const char *str, long n)
 {
-   char buf[BUFSIZ];
-   long i = 0;
+   char *buf = NULL;
+   size_t size = 0;
+   ssize_t len;
+   unsigned long i = 0;
 
-   while(i < n && fgets(buf, sizeof buf, fp))
-   if(buf[strlen(buf)-1] == '
')
+   while(i < n && ((len = agetline(&buf, &size, fp) != -1)))
+   if(len && buf[len - 1] == '
')
i++;
+   free(buf);
concat(fp, str, stdout, "");
 }
 
 static void
 taketail(FILE *fp, const char *str, long n)
 {
-   char **ring;
+   char **ring = NULL;
long i, j;
size_t *size = NULL;
 
if(!(ring = calloc(n, sizeof *ring)) || !(size = calloc(n, sizeof 
*size)))
eprintf("calloc:");
-   for(i = j = 0; afgets(&ring[i], &size[i], fp); i = j = (i+1)%n)
+   for(i = j = 0; agetline(&ring[i], &size[i], fp) != -1; i = j = (i + 1) 
% n)
;
if(ferror(fp))
eprintf("%s: read error:", str);
diff --git a/tr.c b/tr.c
index 527c0e0..388d42f 100644
--- a/tr.c
+++ b/tr.c
@@ -160,7 +160,7 @@ main(int argc, char *argv[])
mapfunc = maptoset;
}
 
-   while(afgets(&buf, &size, stdin))
+   while(agetline(&buf, &size, stdin) != -1)
mapfunc(mappings, buf);
free(buf);
if(ferror(stdin))
diff --git a/uniq.c b/uniq.c
index ee76ee0..03fe72d 100644
--- a/uniq.c
+++ b/uniq.c
@@ -93,7 +93,7 @@ uniq(FILE *fp, const char *str)
char *buf = NULL;
size_t size = 0;
 
-   while(afgets(&buf, &size, fp))
+   while(agetline(&buf, &size, fp) != -1)
uniqline(buf);
 }
 
diff --git a/util/crypt.c b/util/crypt.c
index 589104b..cd9ff32 100644
--- a/util/crypt.c
+++ b/util/crypt.c
@@ -50,7 +50,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
else if(!(cfp = fopen(sumfile, "r")))
eprintf("fopen %s:", sumfile);
 
-   while(afgets(&line, &bufsiz, cfp)) {
+   while(agetline(&line, &bufsiz, cfp) != -1) {
if(!(file = strstr(line, "  "))) {
formatsucks++;
continue;
diff --git a/util/getlines.c b/util/getlines.c
index f1c3453..4d66acf 100644
--- a/util/getlines.c
+++ b/util/getlines.c
@@ -10,10 +10,10 @@ void
 getlines(FILE *fp, struct linebuf *b)
 {
char *line = NULL, **nline;
-   size_t size = 0;
-   size_t linelen;
+   size_t size = 0, linelen;
+   ssize_t len;
 
-   while(afgets(&line, &size, fp)) {
+   while((len = agetline(&line, &size, fp)) != -1) {
if(++b->nlines > b->capacity) {
   

[hackers] [sbase] add -t flag to sort || Jakob Kramer

2014-06-02 Thread git
commit 7d1fd2621ed35fc3eb066e5ff4b886710b5564f8
Author: Jakob Kramer 
Date:   Thu May 15 20:08:17 2014 +0200

add -t flag to sort

diff --git a/sort.1 b/sort.1
index 955cebd..12fb95d 100644
--- a/sort.1
+++ b/sort.1
@@ -4,9 +4,10 @@ sort \- sort lines
 .SH SYNOPSIS
 .B sort
 .RB [ \-bnru ]
+.RB [ \-t
+.IR delim ]
 .RB [ \-k
-.I key
-.R ]...
+.IR key ]...
 .RI [ file ...]
 .SH DESCRIPTION
 .B sort
@@ -17,16 +18,7 @@ given, sort reads from stdin.
 .B \-b
 skip leading whitespace of columns when sorting.
 .TP
-.B \-n
-perform a numeric sort.
-.TP
-.B \-r
-reverses the sort.
-.TP
-.B \-u
-prints equal lines only once.
-.TP
-.B \-k key
+.BI \-k \ key
 specifies a key definition of the form
 .BR S [. s ][ f ][, E [. e ][ f ]]
 where
@@ -50,3 +42,15 @@ can be used to specify options
 that only apply to this key definition.
 .B b
 is special in that it only applies to the column that it was specified after.
+.TP
+.B \-n
+perform a numeric sort.
+.TP
+.B \-r
+reverses the sort.
+.TP
+.BI \-t \ delim
+specifies the field delimiter.
+.TP
+.B \-u
+prints equal lines only once.
diff --git a/sort.c b/sort.c
index a00e902..b0b9131 100644
--- a/sort.c
+++ b/sort.c
@@ -34,20 +34,19 @@ static struct kdlist *tail = NULL;
 static void addkeydef(char *, int);
 static void freelist(void);
 static int linecmp(const char **, const char **);
-static char *next_nonblank(char *);
-static char *next_blank(char *);
+static char *skipblank(char *);
 static int parse_flags(char **, int *, int);
 static int parse_keydef(struct keydef *, char *, int);
-static char *skip_columns(char *, size_t, bool);
-static char *end_column(char *);
+static char *nextcol(char *);
 static char *columns(char *, const struct keydef *);
 
 static bool uflag = false;
+static char *fieldsep = NULL;
 
 static void
 usage(void)
 {
-   enprintf(2, "usage: %s [-bnru] [-k def]... [file...]
", argv0);
+   enprintf(2, "usage: %s [-bnru] [-t delim] [-k def]... [file...]
", argv0);
 }
 
 int
@@ -59,21 +58,26 @@ main(int argc, char *argv[])
int global_flags = 0;
 
ARGBEGIN {
+   case 'b':
+   global_flags |= MOD_STARTB | MOD_ENDB;
+   break;
+   case 'k':
+   addkeydef(EARGF(usage()), global_flags);
+   break;
case 'n':
global_flags |= MOD_N;
break;
case 'r':
global_flags |= MOD_R;
break;
+   case 't':
+   fieldsep = EARGF(usage());
+   if(strlen(fieldsep) != 1)
+   usage();
+   break;
case 'u':
uflag = true;
break;
-   case 'b':
-   global_flags |= MOD_STARTB | MOD_ENDB;
-   break;
-   case 'k':
-   addkeydef(EARGF(usage()), global_flags);
-   break;
default:
usage();
} ARGEND;
@@ -224,7 +228,7 @@ parse_keydef(struct keydef *kd, char *s, int flags)
 }
 
 static char *
-next_nonblank(char *s)
+skipblank(char *s)
 {
while(*s && isblank(*s))
s++;
@@ -232,51 +236,43 @@ next_nonblank(char *s)
 }
 
 static char *
-next_blank(char *s)
+nextcol(char *s)
 {
-   while(*s && !isblank(*s))
-   s++;
-   return s;
-}
-
-static char *
-skip_columns(char *s, size_t n, bool bflag)
-{
-   size_t i;
-
-   for(i = 0; i < n; i++) {
-   if(i > 0)
-   s = end_column(s);
-   if(bflag)
-   s = next_nonblank(s);
+   if(fieldsep == NULL) {
+   s = skipblank(s);
+   while(*s && !isblank(*s))
+   s++;
+   } else {
+   if(strchr(s, *fieldsep) == NULL)
+   s = strchr(s, '



[hackers] [ubase] Add initial implementation of login(1) || sin

2014-06-02 Thread git
commit 0a3ed68d2500c2989545b3bf0af5ebc0b50bec7a
Author: sin 
Date:   Mon Jun 2 14:00:55 2014 +0100

Add initial implementation of login(1)

No shadow support atm.

diff --git a/Makefile b/Makefile
index ac61c7d..fe87548 100644
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,7 @@ SRC = \
id.c\
insmod.c\
killall5.c  \
+   login.c \
lsmod.c \
lsusb.c \
mknod.c \
diff --git a/login.c b/login.c
new file mode 100644
index 000..3adf188
--- /dev/null
+++ b/login.c
@@ -0,0 +1,109 @@
+/* See LICENSE file for copyright and license details. */
+#define _XOPEN_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "config.h"
+#include "util.h"
+
+static int dologin(struct passwd *, int);
+
+static void
+usage(void)
+{
+   eprintf("usage: %s [-p] username
", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+   struct passwd *pw;
+   uid_t uid;
+   gid_t gid;
+   char *pass, *cryptpass;
+   int pflag = 0;
+
+   ARGBEGIN {
+   case 'p':
+   pflag = 1;
+   break;
+   default:
+   usage();
+   } ARGEND;
+
+   if (argc < 1)
+   usage();
+
+   errno = 0;
+   pw = getpwnam(argv[0]);
+   if (errno)
+   eprintf("getpwnam: %s:", argv[0]);
+   else if (!pw)
+   eprintf("who are you?
");
+
+   switch (pw->pw_passwd[0]) {
+   case '!':
+   case '*':
+   eprintf("Denied
");
+   }
+
+   if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '



[hackers] [ubase] Remember to #define _XOPEN_SOURCE for crypt() || sin

2014-06-02 Thread git
commit e992efc8fbdedfc493236e93258800efe8636942
Author: sin 
Date:   Mon Jun 2 14:55:21 2014 +0100

Remember to #define _XOPEN_SOURCE for crypt()

diff --git a/su.c b/su.c
index d24157a..0d639e1 100644
--- a/su.c
+++ b/su.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#define _XOPEN_SOURCE
 #include 
 #include 
 #include 




[hackers] [ubase] Consistent error reporting || sin

2014-06-02 Thread git
commit 6f7995b65aa51daf168eaff7015fe379f2a43bd6
Author: sin 
Date:   Mon Jun 2 16:15:03 2014 +0100

Consistent error reporting

diff --git a/su.c b/su.c
index 0d639e1..8484298 100644
--- a/su.c
+++ b/su.c
@@ -67,7 +67,7 @@ main(int argc, char *argv[])
switch (spw->sp_pwdp[0]) {
case '!':
case '*':
-   eprintf("Denied.
");
+   eprintf("Denied
");
case '$':
break;
default:




[hackers] [ubase] Add login(1) manpage || sin

2014-06-02 Thread git
commit 1988901b7df40fb70eb7e39ac8cfe5e4f4cc7fa7
Author: sin 
Date:   Mon Jun 2 16:41:07 2014 +0100

Add login(1) manpage

diff --git a/Makefile b/Makefile
index fe87548..e55d770 100644
--- a/Makefile
+++ b/Makefile
@@ -67,6 +67,7 @@ MAN1 = \
fallocate.1 \
free.1  \
id.1\
+   login.1 \
mknod.1 \
mountpoint.1\
pagesize.1  \
diff --git a/login.1 b/login.1
new file mode 100644
index 000..e69f692
--- /dev/null
+++ b/login.1
@@ -0,0 +1,16 @@
+.TH LOGIN 1 ubase-VERSION
+.SH NAME
+BloginR - Log into the system
+.SH SYNOPSIS
+BloginR [B-pR] IuserR
+.SH DESCRIPTION
+BloginR logs the IuserR into the system.  It sets BHOMER,
+BSHELLR, BUSERR, BLOGNAMER and the BPATHR environment
+variables and invokes the login shell as specified in I/etc/passwdR.
+.SH OPTIONS
+.TP
+B-pR
+Preserve the environment.
+.SH BUGS
+.TP
+There is no support for shadow files.




[hackers] [ubase] Not all password entries start with '$' || sin

2014-06-02 Thread git
commit d06854177948725d7c26e0b018bdfe5aa698a747
Author: sin 
Date:   Mon Jun 2 16:50:22 2014 +0100

Not all password entries start with '$'

Respect old DES :)

diff --git a/su.c b/su.c
index 8484298..722675d 100644
--- a/su.c
+++ b/su.c
@@ -68,10 +68,6 @@ main(int argc, char *argv[])
case '!':
case '*':
eprintf("Denied
");
-   case '$':
-   break;
-   default:
-   eprintf("Invalid shadow record
");
}
 
uid = getuid();




[hackers] [ubase] Add login(1) to README || sin

2014-06-02 Thread git
commit 9146cebd97151057922a7208958822b4d71f5814
Author: sin 
Date:   Mon Jun 2 16:49:56 2014 +0100

Add login(1) to README

diff --git a/README b/README
index 7cf5f95..379f2be 100644
--- a/README
+++ b/README
@@ -7,8 +7,8 @@ much simpler.
 The following programs are currently implemented:
 
 chvt clear ctrlaltdel df dmesg  eject fallocate free getty halt id
-insmod killall5 lsmod lsusb mknod mkswap mount mountpoint pagesize
-pidof  pivot_root   ps  respawn  rmmod  stat   su  swapoff  swapon
+insmod killall5  login lsmod  lsusb mknod mkswap  mount mountpoint
+pagesize pidof pivot_root ps respawn  rmmod stat su swapoff swapon
 switch_root sysctl truncate umount unshare uptime watch who
 
 The complement  of ubase  is sbase[1] which  mostly follows  POSIX and




[hackers] [ubase] Print getpass() errors on a newline || sin

2014-06-02 Thread git
commit aaea1e9ff71a4ea5aa1da684a5c2a98a3755c2c7
Author: sin 
Date:   Mon Jun 2 17:02:01 2014 +0100

Print getpass() errors on a newline

diff --git a/login.c b/login.c
index 3adf188..c2f628f 100644
--- a/login.c
+++ b/login.c
@@ -67,9 +67,9 @@ main(int argc, char *argv[])
 ioctl(STDIN_FILENO, TCFLSH, (void *)0);
 
pass = getpass("Password: ");
+   putchar('
');
if (!pass)
eprintf("getpass:");
-   putchar('
');
cryptpass = crypt(pass, pw->pw_passwd);
explicit_bzero(pass, strlen(pass));
if (!cryptpass)




[hackers] [ubase] Simplify login || FRIGN

2014-06-02 Thread git
commit af65094dbe9ad4287ce5ed093eed909e48957965
Author: FRIGN 
Date:   Mon Jun 2 18:04:12 2014 +0200

Simplify login

Remove some unnecessary local values, simplify the exec-call at the end
(we don't need the separate array) and print clearer and more consistent
error-messages.

diff --git a/login.c b/login.c
index c2f628f..3c8d6e0 100644
--- a/login.c
+++ b/login.c
@@ -24,8 +24,6 @@ int
 main(int argc, char *argv[])
 {
struct passwd *pw;
-   uid_t uid;
-   gid_t gid;
char *pass, *cryptpass;
int pflag = 0;
 
@@ -50,15 +48,12 @@ main(int argc, char *argv[])
switch (pw->pw_passwd[0]) {
case '!':
case '*':
-   eprintf("Denied
");
+   eprintf("denied
");
}
 
if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '



[hackers] [ubase] use lowercase for errors || sin

2014-06-02 Thread git
commit 3046b513fc4161c2611b51ae0b0c89107750afe3
Author: sin 
Date:   Mon Jun 2 17:14:53 2014 +0100

use lowercase for errors

diff --git a/su.c b/su.c
index 722675d..a274aae 100644
--- a/su.c
+++ b/su.c
@@ -67,7 +67,7 @@ main(int argc, char *argv[])
switch (spw->sp_pwdp[0]) {
case '!':
case '*':
-   eprintf("Denied
");
+   eprintf("denied
");
}
 
uid = getuid();




[hackers] [ubase] /bin is good enough || sin

2014-06-02 Thread git
commit c7b6aacb5c96a02d0459ccb9d1daa86dad32e5cb
Author: sin 
Date:   Mon Jun 2 17:14:29 2014 +0100

/bin is good enough

diff --git a/config.def.h b/config.def.h
index a85d6bd..20f25b5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,4 +1,4 @@
 /* See LICENSE file for copyright and license details. */
 
-#define ENV_SUPATH 
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-#define ENV_PATH   
"/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
+#define ENV_SUPATH "/bin"
+#define ENV_PATH   "/bin"




[hackers] [ubase] Be consistent with logic(1) usage || sin

2014-06-02 Thread git
commit ad4b24a0877e5ea8a903a0bc53d433363603fb94
Author: sin 
Date:   Mon Jun 2 17:33:17 2014 +0100

Be consistent with logic(1) usage

diff --git a/login.1 b/login.1
index e69f692..ad25e9d 100644
--- a/login.1
+++ b/login.1
@@ -2,9 +2,9 @@
 .SH NAME
 BloginR - Log into the system
 .SH SYNOPSIS
-BloginR [B-pR] IuserR
+BloginR [B-pR] IusernameR
 .SH DESCRIPTION
-BloginR logs the IuserR into the system.  It sets BHOMER,
+BloginR logs the IusernameR into the system.  It sets BHOMER,
 BSHELLR, BUSERR, BLOGNAMER and the BPATHR environment
 variables and invokes the login shell as specified in I/etc/passwdR.
 .SH OPTIONS




[hackers] [ubase] Be consistent with login(1) usage || sin

2014-06-02 Thread git
commit b6007ba92b85433ba228da38ae676d9c68aa4eb2
Author: sin 
Date:   Mon Jun 2 17:33:17 2014 +0100

Be consistent with login(1) usage

diff --git a/login.1 b/login.1
index e69f692..ad25e9d 100644
--- a/login.1
+++ b/login.1
@@ -2,9 +2,9 @@
 .SH NAME
 BloginR - Log into the system
 .SH SYNOPSIS
-BloginR [B-pR] IuserR
+BloginR [B-pR] IusernameR
 .SH DESCRIPTION
-BloginR logs the IuserR into the system.  It sets BHOMER,
+BloginR logs the IusernameR into the system.  It sets BHOMER,
 BSHELLR, BUSERR, BLOGNAMER and the BPATHR environment
 variables and invokes the login shell as specified in I/etc/passwdR.
 .SH OPTIONS




[hackers] [ubase] Check if stdin is a tty || sin

2014-06-03 Thread git
commit c4c1feac2a7cba8b2c5282810a30b192d0e30623
Author: sin 
Date:   Tue Jun 3 10:45:27 2014 +0100

Check if stdin is a tty

Some indentation changes as well.

diff --git a/login.c b/login.c
index 3c8d6e0..b9720e4 100644
--- a/login.c
+++ b/login.c
@@ -38,6 +38,9 @@ main(int argc, char *argv[])
if (argc < 1)
usage();
 
+   if (isatty(STDIN_FILENO) == 0)
+   eprintf("stdin is not a tty
");
+
errno = 0;
pw = getpwnam(argv[0]);
if (errno)
@@ -59,7 +62,7 @@ main(int argc, char *argv[])
goto login;
 
/* Flush pending input */
-ioctl(STDIN_FILENO, TCFLSH, (void *)0);
+   ioctl(STDIN_FILENO, TCFLSH, (void *)0);
 
pass = getpass("Password: ");
putchar('
');




[hackers] [ubase] I am stupid. || sin

2014-06-03 Thread git
commit 0de4f5fd9fdfb3106a6ff2da2d31ad9f9a702aeb
Author: sin 
Date:   Tue Jun 3 11:03:25 2014 +0100

I am stupid.

diff --git a/login.c b/login.c
index 92979cf..36de069 100644
--- a/login.c
+++ b/login.c
@@ -117,11 +117,11 @@ dologin(struct passwd *pw, int preserve)
 {
if (preserve == 0)
clearenv();
-   setenv("HOME", pw->pw_dir, preserve);
-   setenv("SHELL", pw->pw_shell, preserve);
-   setenv("USER", pw->pw_name, preserve);
-   setenv("LOGNAME", pw->pw_name, preserve);
-   setenv("PATH", ENV_PATH, preserve);
+   setenv("HOME", pw->pw_dir, !preserve);
+   setenv("SHELL", pw->pw_shell, !preserve);
+   setenv("USER", pw->pw_name, !preserve);
+   setenv("LOGNAME", pw->pw_name, !preserve);
+   setenv("PATH", ENV_PATH, !preserve);
if (chdir(pw->pw_dir) < 0)
eprintf("chdir %s:", pw->pw_dir);
execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);




[hackers] [ubase] Remove BUGS section from login.1 - we now have shadow support || sin

2014-06-03 Thread git
commit e5d539a76f0335da2a1e0c495c16ee60fdff1d01
Author: sin 
Date:   Tue Jun 3 11:03:42 2014 +0100

Remove BUGS section from login.1 - we now have shadow support

diff --git a/login.1 b/login.1
index ad25e9d..e810c73 100644
--- a/login.1
+++ b/login.1
@@ -11,6 +11,3 @@ variables and invokes the login shell as specified in 
I/etc/passwdR.
 .TP
 B-pR
 Preserve the environment.
-.SH BUGS
-.TP
-There is no support for shadow files.




[hackers] [ubase] Add /etc/passwd support to su(1) || sin

2014-06-03 Thread git
commit bd4b6f4e47ae91b9d9c7a47874be5f4847e6a63b
Author: sin 
Date:   Tue Jun 3 12:09:25 2014 +0100

Add /etc/passwd support to su(1)

diff --git a/su.c b/su.c
index a274aae..2c32338 100644
--- a/su.c
+++ b/su.c
@@ -58,42 +58,66 @@ main(int argc, char *argv[])
srand(time(NULL));
 
errno = 0;
-   spw = getspnam(usr);
+   pw = getpwnam(usr);
if (errno)
-   eprintf("getspnam: %s:", usr);
-   else if (!spw)
+   eprintf("getpwnam: %s:", usr);
+   else if (!pw)
eprintf("who are you?
");
 
-   switch (spw->sp_pwdp[0]) {
+   switch (pw->pw_passwd[0]) {
case '!':
case '*':
eprintf("denied
");
}
 
+   /* Empty password? Su now */
+   if (pw->pw_passwd[0] == '



[hackers] [ubase] Remove explicit_bzero() calls || sin

2014-06-03 Thread git
commit 2f10d16b9fc907a05a3b40573a614a561a40d68f
Author: sin 
Date:   Tue Jun 3 12:13:48 2014 +0100

Remove explicit_bzero() calls

diff --git a/login.c b/login.c
index 36de069..a1cb0e2 100644
--- a/login.c
+++ b/login.c
@@ -85,16 +85,12 @@ main(int argc, char *argv[])
eprintf("denied
");
}
cryptpass = crypt(pass, spw->sp_pwdp);
-   explicit_bzero(pass, strlen(pass));
if (!cryptpass)
eprintf("crypt:");
if (strcmp(cryptpass, spw->sp_pwdp) != 0)
eprintf("login failed
");
-   explicit_bzero(cryptpass, strlen(cryptpass));
-   explicit_bzero(spw, sizeof *spw);
} else {
cryptpass = crypt(pass, pw->pw_passwd);
-   explicit_bzero(pass, strlen(pass));
if (!cryptpass)
eprintf("crypt:");
if (strcmp(cryptpass, pw->pw_passwd) != 0)
diff --git a/su.c b/su.c
index 2c32338..f5ac7d9 100644
--- a/su.c
+++ b/su.c
@@ -101,7 +101,6 @@ main(int argc, char *argv[])
if (strcmp(cryptpass, spw->sp_pwdp) != 0)
eprintf(randreply());
}
-   explicit_bzero(spw, sizeof *spw);
} else {
if (uid) {
cryptpass = crypt(pass, pw->pw_passwd);
@@ -112,11 +111,6 @@ main(int argc, char *argv[])
}
}
 
-   if (uid) {
-   explicit_bzero(pass, strlen(pass));
-   explicit_bzero(cryptpass, strlen(cryptpass));
-   }
-
 dosu:
if (initgroups(usr, pw->pw_gid) < 0)
eprintf("initgroups:");




[hackers] [ubase] Simplify dologin() in su(1) || sin

2014-06-03 Thread git
commit b8dbf05ce7aee91e1cf646840f7cc7a8c7827ba9
Author: sin 
Date:   Tue Jun 3 12:24:17 2014 +0100

Simplify dologin() in su(1)

Exec the user's shell with -l to fake a login.

diff --git a/su.c b/su.c
index f5ac7d9..2f7eace 100644
--- a/su.c
+++ b/su.c
@@ -16,7 +16,6 @@
 extern char **environ;
 
 static const char *randreply(void);
-static char *msetenv(const char *, const char *);
 static void dologin(struct passwd *);
 
 static void
@@ -161,39 +160,21 @@ randreply(void)
return replies[rand() % LEN(replies)];
 }
 
-static char *
-msetenv(const char *name, const char *value)
-{
-   char *buf;
-   size_t sz;
-
-   sz = strlen(name) + strlen(value) + 2;
-   buf = emalloc(sz);
-   snprintf(buf, sz, "%s=%s", name, value);
-   return buf;
-}
-
 static void
 dologin(struct passwd *pw)
 {
-   char shbuf[strlen(pw->pw_shell) + 1];
-   char * const *newargv;
-   char * const *newenv;
-
-   strcpy(shbuf, pw->pw_shell);
-   newargv = (char *const[]){shbuf, NULL};
-   newenv = (char *const[]){
-   msetenv("HOME", pw->pw_dir),
-   msetenv("SHELL", pw->pw_shell),
-   msetenv("USER", pw->pw_name),
-   msetenv("LOGNAME", pw->pw_name),
-   msetenv("TERM", getenv("TERM")),
-   msetenv("PATH",
-   strcmp(pw->pw_name, "root") == 0 ?
-   ENV_SUPATH : ENV_PATH),
-   NULL
-   };
+   char *term = getenv("TERM");
+   clearenv();
+   setenv("HOME", pw->pw_dir, 1);
+   setenv("SHELL", pw->pw_shell, 1);
+   setenv("USER", pw->pw_name, 1);
+   setenv("LOGNAME", pw->pw_name, 1);
+   setenv("TERM", term ? term : "vt100", 1);
+   if (strcmp(pw->pw_name, "root") == 0)
+   setenv("PATH", ENV_SUPATH, 1);
+   else
+   setenv("PATH", ENV_PATH, 1);
if (chdir(pw->pw_dir) < 0)
eprintf("chdir %s:", pw->pw_dir);
-   execve(pw->pw_shell, newargv, newenv);
+   execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);
 }




[hackers] [ubase] Inform the user if exec*() fails || sin

2014-06-03 Thread git
commit da215823a36a86eaaa593098c0244e5d9e5e08bb
Author: sin 
Date:   Tue Jun 3 12:29:16 2014 +0100

Inform the user if exec*() fails

diff --git a/su.c b/su.c
index 2f7eace..8b2d154 100644
--- a/su.c
+++ b/su.c
@@ -16,7 +16,7 @@
 extern char **environ;
 
 static const char *randreply(void);
-static void dologin(struct passwd *);
+static int dologin(struct passwd *);
 
 static void
 usage(void)
@@ -119,7 +119,7 @@ dosu:
eprintf("setuid:");
 
if (lflag) {
-   dologin(pw);
+   return dologin(pw);
} else {
newargv = (char *const[]){pw->pw_shell, NULL};
if (!pflag) {
@@ -136,8 +136,10 @@ dosu:
setenv("PATH", ENV_PATH, 1);
execve(pflag ? getenv("SHELL") : pw->pw_shell,
   newargv, environ);
+   weprintf("execve %s:", pw->pw_shell);
+   return (errno == ENOENT) ? 127 : 126;
}
-   return (errno == ENOENT) ? 127 : 126;
+   return EXIT_SUCCESS;
 }
 
 static const char *
@@ -160,7 +162,7 @@ randreply(void)
return replies[rand() % LEN(replies)];
 }
 
-static void
+static int
 dologin(struct passwd *pw)
 {
char *term = getenv("TERM");
@@ -177,4 +179,6 @@ dologin(struct passwd *pw)
if (chdir(pw->pw_dir) < 0)
eprintf("chdir %s:", pw->pw_dir);
execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);
+   weprintf("execlp %s:", pw->pw_shell);
+   return (errno == ENOENT) ? 127 : 126;
 }




[hackers] [ubase] Use correction function name in error message || sin

2014-06-03 Thread git
commit 323f6be8ef0e084a3d468d48573ab9b9e7b94f66
Author: sin 
Date:   Tue Jun 3 12:27:38 2014 +0100

Use correction function name in error message

diff --git a/login.c b/login.c
index a1cb0e2..4d74dd1 100644
--- a/login.c
+++ b/login.c
@@ -121,6 +121,6 @@ dologin(struct passwd *pw, int preserve)
if (chdir(pw->pw_dir) < 0)
eprintf("chdir %s:", pw->pw_dir);
execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);
-   weprintf("execvp %s:", pw->pw_shell);
+   weprintf("execlp %s:", pw->pw_shell);
return (errno == ENOENT) ? 127 : 126;
 }




[hackers] [ubase] Use -std=c99 and -pedantic in default config.mk || sin

2014-06-03 Thread git
commit 604b5de69d093ec74c374490a858933c100e8c34
Author: sin 
Date:   Tue Jun 3 12:34:52 2014 +0100

Use -std=c99 and -pedantic in default config.mk

diff --git a/config.mk b/config.mk
index 5ea979f..b380b76 100644
--- a/config.mk
+++ b/config.mk
@@ -9,5 +9,5 @@ MANPREFIX = $(PREFIX)/share/man
 #CC = musl-gcc
 LD = $(CC)
 CPPFLAGS = -D_GNU_SOURCE
-CFLAGS   = -Wall -Wextra $(CPPFLAGS)
+CFLAGS   = -std=c99 -Wall -Wextra -pedantic $(CPPFLAGS)
 LDFLAGS  = -s -lcrypt # -static




[hackers] [ubase] Update TODO || sin

2014-06-03 Thread git
commit 0daa5a820639f992786d93047ac695939edeea61
Author: sin 
Date:   Tue Jun 3 12:38:01 2014 +0100

Update TODO

diff --git a/TODO b/TODO
index ec7272e..14dbc82 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,6 @@
-Tools
-=
+Tools to be implemented
+===
+
  * vmstat(8)
  * top(1)
  * Better ps(1) support
@@ -9,5 +10,10 @@ Tools
  * lspci
  * mkswap [-L]
  * passwd
+ * adduser
+ * addgroup
+ * rmuser
+ * rmgroup
  * login
  * dd
+ * ifconfig




[hackers] [ubase] Remove login from TODO || sin

2014-06-03 Thread git
commit df6f793d5788933b121b9da35a8db99909a21b13
Author: sin 
Date:   Tue Jun 3 12:38:38 2014 +0100

Remove login from TODO

diff --git a/TODO b/TODO
index 14dbc82..bcb8cd3 100644
--- a/TODO
+++ b/TODO
@@ -14,6 +14,5 @@ Tools to be implemented
  * addgroup
  * rmuser
  * rmgroup
- * login
  * dd
  * ifconfig




[hackers] [ubase] Add hwclock to TODO || sin

2014-06-03 Thread git
commit c4051021c90a5af2b62cd9fcdb800cc992eb2d7c
Author: sin 
Date:   Tue Jun 3 12:45:29 2014 +0100

Add hwclock to TODO

diff --git a/TODO b/TODO
index bcb8cd3..1645632 100644
--- a/TODO
+++ b/TODO
@@ -16,3 +16,4 @@ Tools to be implemented
  * rmgroup
  * dd
  * ifconfig
+ * hwclock




[hackers] [ubase] Add initial version of hwclock(8) || sin

2014-06-03 Thread git
commit dacfb76c75bbd9a5020d4a3bd22b993e1e9dfebd
Author: sin 
Date:   Tue Jun 3 14:46:27 2014 +0100

Add initial version of hwclock(8)

diff --git a/Makefile b/Makefile
index e55d770..d0b6acd 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ include config.mk
 .POSIX:
 .SUFFIXES: .c .o
 
-HDR = arg.h config.def.h proc.h reboot.h util.h
+HDR = arg.h config.def.h proc.h reboot.h rtc.h util.h
 LIB = \
util/agetcwd.o\
util/apathmax.o   \
@@ -29,6 +29,7 @@ SRC = \
free.c  \
getty.c \
halt.c  \
+   hwclock.c   \
id.c\
insmod.c\
killall5.c  \
diff --git a/hwclock.c b/hwclock.c
new file mode 100644
index 000..093d5bd
--- /dev/null
+++ b/hwclock.c
@@ -0,0 +1,106 @@
+/* See LICENSE file for copyright and license details. */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "rtc.h"
+#include "util.h"
+
+static void echotime(char *);
+static void readrtctm(struct tm *, int);
+static void writertctm(struct tm *, int);
+static void writetime(char *);
+
+static void
+usage(void)
+{
+   eprintf("usage: %s [-rw] [-u]
", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+   char *dev = "/dev/rtc";
+   int rflag = 0;
+   int wflag = 0;
+
+   ARGBEGIN {
+   case 'r':
+   rflag = 1;
+   break;
+   case 'w':
+   wflag = 1;
+   break;
+   case 'u':
+   break;
+   default:
+   usage();
+   } ARGEND;
+
+   if ((rflag ^ wflag) == 0)
+   eprintf("missing or incompatible function
");
+
+   /* Only UTC support at the moment */
+   setenv("TZ", "UTC0", 1);
+   tzset();
+
+   if (rflag == 1)
+   echotime(dev);
+   else if (wflag == 1)
+   writetime(dev);
+
+   return EXIT_SUCCESS;
+}
+
+static void
+echotime(char *dev)
+{
+   struct tm tm;
+   time_t t;
+   int fd;
+
+   fd = open(dev, O_RDONLY);
+   if (fd < 0)
+   eprintf("open %s:", dev);
+   readrtctm(&tm, fd);
+   t = mktime(&tm);
+   printf("%s", asctime(localtime(&t)));
+   close(fd);
+}
+
+static void
+readrtctm(struct tm *tm, int fd)
+{
+   memset(tm, 0, sizeof(*tm));
+   ioctl(fd, RTC_RD_TIME, tm);
+}
+
+static void
+writertctm(struct tm *tm, int fd)
+{
+   ioctl(fd, RTC_SET_TIME, tm);
+}
+
+static void
+writetime(char *dev)
+{
+   struct timeval tv;
+   struct tm *tm;
+   time_t t;
+   int fd;
+
+   fd = open(dev, O_WRONLY);
+   if (fd < 0)
+   eprintf("open %s:", dev);
+   gettimeofday(&tv, NULL);
+   t = tv.tv_sec;
+   tm = gmtime(&t);
+   writertctm(tm, fd);
+   close(fd);
+}
diff --git a/rtc.h b/rtc.h
new file mode 100644
index 000..9dd76c1
--- /dev/null
+++ b/rtc.h
@@ -0,0 +1,2 @@
+#define RTC_RD_TIME_IOR('p', 0x09, struct tm) /* Read RTC time   */
+#define RTC_SET_TIME   _IOW('p', 0x0a, struct tm) /* Set RTC time*/




[hackers] [ubase] Use rtc_time || sin

2014-06-03 Thread git
commit e3d7ffa05c8b658cf79e406baa3dcfe111fe4928
Author: sin 
Date:   Tue Jun 3 15:04:53 2014 +0100

Use rtc_time

diff --git a/hwclock.c b/hwclock.c
index 093d5bd..4193b62 100644
--- a/hwclock.c
+++ b/hwclock.c
@@ -77,14 +77,36 @@ echotime(char *dev)
 static void
 readrtctm(struct tm *tm, int fd)
 {
-   memset(tm, 0, sizeof(*tm));
-   ioctl(fd, RTC_RD_TIME, tm);
+   struct rtc_time rt;
+
+   memset(&rt, 0, sizeof(rt));
+   ioctl(fd, RTC_RD_TIME, &rt);
+   tm->tm_sec = rt.tm_sec;
+   tm->tm_min = rt.tm_min;
+   tm->tm_hour = rt.tm_hour;
+   tm->tm_mday = rt.tm_mday;
+   tm->tm_mon = rt.tm_mon;
+   tm->tm_year = rt.tm_year;
+   tm->tm_wday = rt.tm_wday;
+   tm->tm_yday = rt.tm_yday;
+   tm->tm_isdst = rt.tm_isdst;
 }
 
 static void
 writertctm(struct tm *tm, int fd)
 {
-   ioctl(fd, RTC_SET_TIME, tm);
+   struct rtc_time rt;
+
+   rt.tm_sec = tm->tm_sec;
+   rt.tm_min = tm->tm_min;
+   rt.tm_hour = tm->tm_hour;
+   rt.tm_mday = tm->tm_mday;
+   rt.tm_mon = tm->tm_mon;
+   rt.tm_year = tm->tm_year;
+   rt.tm_wday = tm->tm_wday;
+   rt.tm_yday = tm->tm_yday;
+   rt.tm_isdst = tm->tm_isdst;
+   ioctl(fd, RTC_SET_TIME, &rt);
 }
 
 static void
diff --git a/rtc.h b/rtc.h
index 9dd76c1..e4135a7 100644
--- a/rtc.h
+++ b/rtc.h
@@ -1,2 +1,20 @@
-#define RTC_RD_TIME_IOR('p', 0x09, struct tm) /* Read RTC time   */
-#define RTC_SET_TIME   _IOW('p', 0x0a, struct tm) /* Set RTC time*/
+/*
+ * The struct used to pass data via the following ioctl. Similar to the
+ * struct tm in , but it needs to be here so that the kernel
+ * source is self contained, allowing cross-compiles, etc. etc.
+ */
+
+struct rtc_time {
+   int tm_sec;
+   int tm_min;
+   int tm_hour;
+   int tm_mday;
+   int tm_mon;
+   int tm_year;
+   int tm_wday;
+   int tm_yday;
+   int tm_isdst;
+};
+
+#define RTC_RD_TIME_IOR('p', 0x09, struct rtc_time) /* Read RTC time   */
+#define RTC_SET_TIME   _IOW('p', 0x0a, struct rtc_time) /* Set RTC time*/




[hackers] [ubase] Remove -pedantic from default config.mk || sin

2014-06-03 Thread git
commit 5dd629fd421029831eebeac70f794b1a7a8b5d47
Author: sin 
Date:   Tue Jun 3 15:33:29 2014 +0100

Remove -pedantic from default config.mk

diff --git a/config.mk b/config.mk
index b380b76..6587d3a 100644
--- a/config.mk
+++ b/config.mk
@@ -9,5 +9,5 @@ MANPREFIX = $(PREFIX)/share/man
 #CC = musl-gcc
 LD = $(CC)
 CPPFLAGS = -D_GNU_SOURCE
-CFLAGS   = -std=c99 -Wall -Wextra -pedantic $(CPPFLAGS)
+CFLAGS   = -std=c99 -Wall -Wextra $(CPPFLAGS)
 LDFLAGS  = -s -lcrypt # -static




[hackers] [ubase] Add hwclock in README || sin

2014-06-03 Thread git
commit cd0c6cf5b8c28017b2cd13191477123864e5e1bd
Author: sin 
Date:   Tue Jun 3 15:41:59 2014 +0100

Add hwclock in README

diff --git a/README b/README
index 379f2be..ac8d0ee 100644
--- a/README
+++ b/README
@@ -6,10 +6,11 @@ much simpler.
 
 The following programs are currently implemented:
 
-chvt clear ctrlaltdel df dmesg  eject fallocate free getty halt id
-insmod killall5  login lsmod  lsusb mknod mkswap  mount mountpoint
-pagesize pidof pivot_root ps respawn  rmmod stat su swapoff swapon
-switch_root sysctl truncate umount unshare uptime watch who
+chvt clear  ctrlaltdel df  dmesg eject  fallocate free  getty halt
+hwclock id  insmod killall5 login  lsmod lsusb mknod  mkswap mount
+mountpoint  pagesize pidof  pivot_root  ps respawn  rmmod stat  su
+swapoff swapon  switch_root sysctl truncate umount  unshare uptime
+watch who
 
 The complement  of ubase  is sbase[1] which  mostly follows  POSIX and
 provides all the portable tools.  Together they are intended to form a




[hackers] [ubase] Implement -s support for hwclock(8) || sin

2014-06-03 Thread git
commit 5836145a5c4518131303027a47afb42679cc0da1
Author: sin 
Date:   Tue Jun 3 15:52:45 2014 +0100

Implement -s support for hwclock(8)

Rename some functions as well.

diff --git a/hwclock.c b/hwclock.c
index 4193b62..a259a98 100644
--- a/hwclock.c
+++ b/hwclock.c
@@ -12,15 +12,16 @@
 #include "rtc.h"
 #include "util.h"
 
-static void echotime(char *);
 static void readrtctm(struct tm *, int);
 static void writertctm(struct tm *, int);
-static void writetime(char *);
+static void show(char *);
+static void hctosys(char *);
+static void systohc(char *);
 
 static void
 usage(void)
 {
-   eprintf("usage: %s [-rw] [-u]
", argv0);
+   eprintf("usage: %s [-rsw] [-u]
", argv0);
 }
 
 int
@@ -28,12 +29,16 @@ main(int argc, char *argv[])
 {
char *dev = "/dev/rtc";
int rflag = 0;
+   int sflag = 0;
int wflag = 0;
 
ARGBEGIN {
case 'r':
rflag = 1;
break;
+   case 's':
+   sflag = 1;
+   break;
case 'w':
wflag = 1;
break;
@@ -43,7 +48,7 @@ main(int argc, char *argv[])
usage();
} ARGEND;
 
-   if ((rflag ^ wflag) == 0)
+   if ((rflag ^ sflag ^ wflag) == 0)
eprintf("missing or incompatible function
");
 
/* Only UTC support at the moment */
@@ -51,30 +56,16 @@ main(int argc, char *argv[])
tzset();
 
if (rflag == 1)
-   echotime(dev);
+   show(dev);
+   else if (sflag == 1)
+   hctosys(dev);
else if (wflag == 1)
-   writetime(dev);
+   systohc(dev);
 
return EXIT_SUCCESS;
 }
 
 static void
-echotime(char *dev)
-{
-   struct tm tm;
-   time_t t;
-   int fd;
-
-   fd = open(dev, O_RDONLY);
-   if (fd < 0)
-   eprintf("open %s:", dev);
-   readrtctm(&tm, fd);
-   t = mktime(&tm);
-   printf("%s", asctime(localtime(&t)));
-   close(fd);
-}
-
-static void
 readrtctm(struct tm *tm, int fd)
 {
struct rtc_time rt;
@@ -110,7 +101,43 @@ writertctm(struct tm *tm, int fd)
 }
 
 static void
-writetime(char *dev)
+show(char *dev)
+{
+   struct tm tm;
+   time_t t;
+   int fd;
+
+   fd = open(dev, O_RDONLY);
+   if (fd < 0)
+   eprintf("open %s:", dev);
+   readrtctm(&tm, fd);
+   t = mktime(&tm);
+   printf("%s", asctime(localtime(&t)));
+   close(fd);
+}
+
+static void
+hctosys(char *dev)
+{
+   struct timeval tv;
+   struct tm tm;
+   int r;
+   int fd;
+
+   fd = open(dev, O_RDONLY);
+   if (fd < 0)
+   eprintf("open %s:", dev);
+   readrtctm(&tm, fd);
+   tv.tv_sec = mktime(&tm);
+   tv.tv_usec = 0;
+   r = settimeofday(&tv, NULL);
+   if (r < 0)
+   eprintf("settimeofday:");
+   close(fd);
+}
+
+static void
+systohc(char *dev)
 {
struct timeval tv;
struct tm *tm;




[hackers] [ubase] Allow to specify the rtc devnode for hwclock(8) || sin

2014-06-03 Thread git
commit 5bbc67aa96b094c1f8edbf6e67ccf64cded7fc3d
Author: sin 
Date:   Tue Jun 3 16:04:53 2014 +0100

Allow to specify the rtc devnode for hwclock(8)

diff --git a/hwclock.c b/hwclock.c
index a259a98..b48d46c 100644
--- a/hwclock.c
+++ b/hwclock.c
@@ -21,7 +21,7 @@ static void systohc(char *);
 static void
 usage(void)
 {
-   eprintf("usage: %s [-rsw] [-u]
", argv0);
+   eprintf("usage: %s [-rsw] [-u] [dev]
", argv0);
 }
 
 int
@@ -48,6 +48,11 @@ main(int argc, char *argv[])
usage();
} ARGEND;
 
+   if (argc > 1)
+   usage();
+   else if (argc == 1)
+   dev = argv[0];
+
if ((rflag ^ sflag ^ wflag) == 0)
eprintf("missing or incompatible function
");
 




[hackers] [ubase] Add hwclock(8) manpage || sin

2014-06-03 Thread git
commit 0d09df4645e4eef556075f31290915f1f22e7c4d
Author: sin 
Date:   Tue Jun 3 16:20:57 2014 +0100

Add hwclock(8) manpage

diff --git a/Makefile b/Makefile
index d0b6acd..a2be343 100644
--- a/Makefile
+++ b/Makefile
@@ -87,6 +87,7 @@ MAN8 = \
ctrlaltdel.8\
getty.8 \
halt.8  \
+   hwclock.8   \
insmod.8\
killall5.8  \
lsmod.8 \
diff --git a/hwclock.8 b/hwclock.8
new file mode 100644
index 000..21b5266
--- /dev/null
+++ b/hwclock.8
@@ -0,0 +1,24 @@
+.TH HWCLOCK 8 ubase-VERSION
+.SH NAME
+BhwclockR - Query or set the hardware clock
+.SH SYNOPSIS
+BhwclockR [B-rswR] [B-uR] [IdevR]
+.SH DESCRIPTION
+BhwclockR is a tool for accessing the hardware clock. You can display
+the current time, set the hardware clock from the System Time, or
+set the System Time from the hardware clock. It currently only works with UTC.
+You can use IdevR to specify the RTC device node absolute path.
+.SH FUNCTIONS
+.TP
+B-rR
+Read the hardware clock and print the time on stdout.
+.TP
+B-sR
+Set the system time from the hardware clock.
+.TP
+B-wR
+Set the hardware clock to the system time.
+.SH OPTIONS
+.TP
+B-uR
+Use UTC. This is the default and only option.




[hackers] [ubase] Print a warning for -w to let the user know that we are assuming UTC || sin

2014-06-03 Thread git
commit 8216a97519e8d9adfc56ede64e44e8574701e531
Author: sin 
Date:   Tue Jun 3 16:24:53 2014 +0100

Print a warning for -w to let the user know that we are assuming UTC

diff --git a/hwclock.c b/hwclock.c
index b48d46c..e26fd73 100644
--- a/hwclock.c
+++ b/hwclock.c
@@ -155,6 +155,7 @@ systohc(char *dev)
gettimeofday(&tv, NULL);
t = tv.tv_sec;
tm = gmtime(&t);
+   weprintf("warning: assuming UTC for systohc
");
writertctm(tm, fd);
close(fd);
 }




[hackers] [ubase] Set TERM to linux if needed for su and login || sin

2014-06-03 Thread git
commit 916b7fed1e5575792a5db6a9340a56ce014b1ecb
Author: sin 
Date:   Tue Jun 3 18:19:31 2014 +0100

Set TERM to linux if needed for su and login

diff --git a/login.c b/login.c
index 4d74dd1..fa01371 100644
--- a/login.c
+++ b/login.c
@@ -117,6 +117,7 @@ dologin(struct passwd *pw, int preserve)
setenv("SHELL", pw->pw_shell, !preserve);
setenv("USER", pw->pw_name, !preserve);
setenv("LOGNAME", pw->pw_name, !preserve);
+   setenv("TERM", "linux", !preserve);
setenv("PATH", ENV_PATH, !preserve);
if (chdir(pw->pw_dir) < 0)
eprintf("chdir %s:", pw->pw_dir);
diff --git a/su.c b/su.c
index 8b2d154..47d3fe7 100644
--- a/su.c
+++ b/su.c
@@ -171,7 +171,7 @@ dologin(struct passwd *pw)
setenv("SHELL", pw->pw_shell, 1);
setenv("USER", pw->pw_name, 1);
setenv("LOGNAME", pw->pw_name, 1);
-   setenv("TERM", term ? term : "vt100", 1);
+   setenv("TERM", term ? term : "linux", 1);
if (strcmp(pw->pw_name, "root") == 0)
setenv("PATH", ENV_SUPATH, 1);
else




[hackers] [ubase] Clarify in login.1 that TERM is set as well || sin

2014-06-03 Thread git
commit d522589a1178b5e82ec0195e01a5c368ccd6687a
Author: sin 
Date:   Tue Jun 3 18:23:03 2014 +0100

Clarify in login.1 that TERM is set as well

diff --git a/login.1 b/login.1
index e810c73..4d13d73 100644
--- a/login.1
+++ b/login.1
@@ -5,7 +5,7 @@
 BloginR [B-pR] IusernameR
 .SH DESCRIPTION
 BloginR logs the IusernameR into the system.  It sets BHOMER,
-BSHELLR, BUSERR, BLOGNAMER and the BPATHR environment
+BSHELLR, BUSERR, BLOGNAMER, BTERMR and the BPATHR environment
 variables and invokes the login shell as specified in I/etc/passwdR.
 .SH OPTIONS
 .TP




[hackers] [ubase] Fix login(1) -p semantincs once and for all || sin

2014-06-03 Thread git
commit 01fa8eec5842f90e8afa60e3429daa87ee104e22
Author: sin 
Date:   Tue Jun 3 18:56:46 2014 +0100

Fix login(1) -p semantincs once and for all

diff --git a/login.1 b/login.1
index 4d13d73..e810c73 100644
--- a/login.1
+++ b/login.1
@@ -5,7 +5,7 @@
 BloginR [B-pR] IusernameR
 .SH DESCRIPTION
 BloginR logs the IusernameR into the system.  It sets BHOMER,
-BSHELLR, BUSERR, BLOGNAMER, BTERMR and the BPATHR environment
+BSHELLR, BUSERR, BLOGNAMER and the BPATHR environment
 variables and invokes the login shell as specified in I/etc/passwdR.
 .SH OPTIONS
 .TP
diff --git a/login.c b/login.c
index fa01371..bc90818 100644
--- a/login.c
+++ b/login.c
@@ -113,12 +113,11 @@ dologin(struct passwd *pw, int preserve)
 {
if (preserve == 0)
clearenv();
-   setenv("HOME", pw->pw_dir, !preserve);
-   setenv("SHELL", pw->pw_shell, !preserve);
-   setenv("USER", pw->pw_name, !preserve);
-   setenv("LOGNAME", pw->pw_name, !preserve);
-   setenv("TERM", "linux", !preserve);
-   setenv("PATH", ENV_PATH, !preserve);
+   setenv("HOME", pw->pw_dir, 1);
+   setenv("SHELL", pw->pw_shell, 1);
+   setenv("USER", pw->pw_name, 1);
+   setenv("LOGNAME", pw->pw_name, 1);
+   setenv("PATH", ENV_PATH, 1);
if (chdir(pw->pw_dir) < 0)
eprintf("chdir %s:", pw->pw_dir);
execlp(pw->pw_shell, pw->pw_shell, "-l", NULL);




[hackers] [sbase] remove unnecessary calls to realloc from tee || Jakob Kramer

2014-06-03 Thread git
commit 2e1580ed2dd9dd81e1c63ff52d906fdeafbb1fe6
Author: Jakob Kramer 
Date:   Tue Jun 3 00:15:52 2014 +0200

remove unnecessary calls to realloc from tee

diff --git a/tee.c b/tee.c
index d78602b..d88e49c 100644
--- a/tee.c
+++ b/tee.c
@@ -16,7 +16,7 @@ main(int argc, char *argv[])
 {
bool aflag = false;
char buf[BUFSIZ];
-   int i, nfps = 1;
+   int i, nfps;
size_t n;
FILE **fps = NULL;
 
@@ -28,16 +28,15 @@ main(int argc, char *argv[])
usage();
} ARGEND;
 
-   if(!(fps = malloc(sizeof *fps)))
-   eprintf("malloc:");
-   fps[nfps-1] = stdout;
+   nfps = argc + 1;
+   if(!(fps = calloc(nfps, sizeof *fps)))
+   eprintf("calloc:");
+
+   for(i = 0; argc > 0; argc--, argv++, i++)
+   if(!(fps[i] = fopen(*argv, aflag ? "a" : "w")))
+   eprintf("fopen %s:", *argv);
+   fps[i] = stdout;
 
-   for(; argc > 0; argc--, argv++) {
-   if(!(fps = realloc(fps, ++nfps * sizeof *fps)))
-   eprintf("realloc:");
-   if(!(fps[nfps-1] = fopen(argv[0], aflag ? "a" : "w")))
-   eprintf("fopen %s:", argv[0]);
-   }
while((n = fread(buf, 1, sizeof buf, stdin)) > 0) {
for(i = 0; i < nfps; i++) {
if(fwrite(buf, 1, n, fps[i]) != n)




[hackers] [ubase] Clarify that hwclock(8) uses /dev/rtc as the default devnode || sin

2014-06-04 Thread git
commit d2dfc053c14dab04870b5520bba42c9a0173c654
Author: sin 
Date:   Wed Jun 4 10:56:20 2014 +0100

Clarify that hwclock(8) uses /dev/rtc as the default devnode

diff --git a/hwclock.8 b/hwclock.8
index 21b5266..8c3ac10 100644
--- a/hwclock.8
+++ b/hwclock.8
@@ -7,7 +7,8 @@
 BhwclockR is a tool for accessing the hardware clock. You can display
 the current time, set the hardware clock from the System Time, or
 set the System Time from the hardware clock. It currently only works with UTC.
-You can use IdevR to specify the RTC device node absolute path.
+You can use IdevR to specify the RTC device node absolute path. By default
+it will use I/dev/rtcR.
 .SH FUNCTIONS
 .TP
 B-rR




[hackers] [ubase] Add initial version of dd(1). || sin

2014-06-04 Thread git
commit 207ba019fda48ef7d84484afbfd56d327dd5e249
Author: sin 
Date:   Wed Jun 4 11:39:00 2014 +0100

Add initial version of dd(1).

This code was written by Sebastian Krahmer and you can find
the original version at https://github.com/stealth/odd.git.

Permission has been granted to release this code under MIT/X
for ubase.  It has been simplified by s...@2f30.org.

Thanks Sebastian!

diff --git a/Makefile b/Makefile
index a2be343..04fe64d 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,7 @@ SRC = \
chvt.c  \
clear.c \
ctrlaltdel.c\
+   dd.c\
df.c\
dmesg.c \
eject.c \
diff --git a/dd.c b/dd.c
new file mode 100644
index 000..9fdf6d9
--- /dev/null
+++ b/dd.c
@@ -0,0 +1,269 @@
+/* (C) 2011-2012 Sebastian Krahmer all rights reserved.
+ *
+ * Optimized dd, to speed up backups etc.
+ *
+ * Permission has been granted to release this code under MIT/X.
+ * The original code is at https://github.com/stealth/odd.  This
+ * version of the code has been modified by s...@2f30.org.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct dd_config {
+   const char *in, *out;
+   uint64_t skip, seek, count, b_in, b_out, rec_in, rec_out;
+   off_t fsize;
+   blksize_t bs;
+   char quiet, nosync, direct;
+   int saved_errno;
+   time_t t_start, t_end;
+};
+
+static int sigint = 0;
+
+static int
+prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
+{
+   struct stat st;
+   int fli = O_RDONLY|O_LARGEFILE|O_NOCTTY, flo = 
O_WRONLY|O_LARGEFILE|O_NOATIME|O_NOCTTY;
+   uid_t euid = 0;
+
+   if (ddc->direct) {
+   fli |= O_DIRECT;
+   flo |= O_DIRECT;
+   }
+
+   if (stat(ddc->in, &st) < 0) {
+   ddc->saved_errno = errno;
+   return -1;
+   }
+
+   euid = geteuid();
+
+   if (!euid || st.st_uid == euid)
+   fli |= O_NOATIME;
+
+   if ((*ifd = open(ddc->in, fli)) < 0) {
+   ddc->saved_errno = errno;
+   return -1;
+   }
+
+   ddc->fsize = st.st_size;
+
+   /* If "bsize" is not given, use optimum of both FS' */
+   if (!ddc->bs) {
+   struct statfs fst;
+   memset(&fst, 0, sizeof(fst));
+   if (statfs(ddc->out, &fst) < 0 || fst.f_bsize == 0)
+   fst.f_bsize = 0x1000;
+   if (fst.f_bsize > st.st_blksize)
+   ddc->bs = fst.f_bsize;
+   else
+   ddc->bs = st.st_blksize;
+   if (ddc->bs == 0)
+   ddc->bs = 0x1000;
+   }
+
+   /* check if device or regular file */
+   if (!S_ISREG(st.st_mode)) {
+   if (S_ISBLK(st.st_mode)) {
+   if (ioctl(*ifd, BLKGETSIZE64, &ddc->fsize) < 0) {
+   ddc->saved_errno = errno;
+   close(*ifd);
+   return -1;
+   }
+   } else {
+   ddc->fsize = (off_t)-1;
+   if (ddc->count)
+   ddc->fsize = ddc->count*ddc->bs;
+   }
+   }
+
+   /* skip and seek are in block items */
+   ddc->skip *= ddc->bs;
+   ddc->seek *= ddc->bs;
+
+   /* skip more bytes than are inside source file? */
+   if (ddc->fsize != (off_t)-1 && ddc->skip >= (uint64_t)ddc->fsize) {
+   ddc->saved_errno = EINVAL;
+   close(*ifd);
+   return -1;
+   }
+
+   if (!ddc->seek)
+   flo |= O_CREAT|O_TRUNC;
+
+   if ((*ofd = open(ddc->out, flo, st.st_mode)) < 0) {
+   ddc->saved_errno = errno;
+   close(*ifd);
+   return -1;
+   }
+
+   lseek(*ifd, ddc->skip, SEEK_SET);
+   lseek(*ofd, ddc->seek, SEEK_SET);
+   posix_fadvise(*ifd, ddc->skip, 0, POSIX_FADV_SEQUENTIAL);
+   posix_fadvise(*ofd, 0, 0, POSIX_FADV_DONTNEED);
+
+   /* count is in block items too */
+   ddc->count *= ddc->bs;
+
+   /* If no count is given, its the filesize minus skip offset */
+   if (ddc->count == 0)
+   ddc->count = ddc->fsize - ddc->skip;
+
+   return 0;
+}
+
+int copy_splice(struct dd_config *ddc)
+{
+int ifd, ofd, p[2] = {-1, -1};
+ssize_t r = 0;
+size_t n = 0;
+if (prepare_copy(ddc, &ifd, &ofd) < 0)
+return -1;
+if (pipe(p) < 0) {
+ddc->saved_errno = errno;
+close(ifd); close(ofd)

[hackers] [ubase] Nuke a harmless warning || sin

2014-06-04 Thread git
commit ca9870afb0c8fe416e90e08dfd38f361da634278
Author: sin 
Date:   Wed Jun 4 12:12:18 2014 +0100

Nuke a harmless warning

diff --git a/dd.c b/dd.c
index 9fdf6d9..f3eeaf2 100644
--- a/dd.c
+++ b/dd.c
@@ -68,7 +68,7 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
memset(&fst, 0, sizeof(fst));
if (statfs(ddc->out, &fst) < 0 || fst.f_bsize == 0)
fst.f_bsize = 0x1000;
-   if (fst.f_bsize > st.st_blksize)
+   if (fst.f_bsize > (unsigned long)st.st_blksize)
ddc->bs = fst.f_bsize;
else
ddc->bs = st.st_blksize;




[hackers] [ubase] Nuke a harmless warning || sin

2014-06-04 Thread git
commit 5c66e30060c4bb62db928bdb6e557a23e2a32160
Author: sin 
Date:   Wed Jun 4 12:12:18 2014 +0100

Nuke a harmless warning

diff --git a/dd.c b/dd.c
index 9fdf6d9..f472c88 100644
--- a/dd.c
+++ b/dd.c
@@ -68,7 +68,7 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
memset(&fst, 0, sizeof(fst));
if (statfs(ddc->out, &fst) < 0 || fst.f_bsize == 0)
fst.f_bsize = 0x1000;
-   if (fst.f_bsize > st.st_blksize)
+   if ((unsigned long)fst.f_bsize > (unsigned long)st.st_blksize)
ddc->bs = fst.f_bsize;
else
ddc->bs = st.st_blksize;




[hackers] [ubase] Use eprintf() wherever possible, add -h to options || sin

2014-06-04 Thread git
commit 7fa098ace67f2089710608f788259931a118acc6
Author: sin 
Date:   Wed Jun 4 12:59:45 2014 +0100

Use eprintf() wherever possible, add -h to options

diff --git a/dd.c b/dd.c
index f472c88..c4db974 100644
--- a/dd.c
+++ b/dd.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include "util.h"
 
 struct dd_config {
const char *in, *out;
@@ -191,8 +192,7 @@ copy(struct dd_config *ddc)
 static void
 usage(void)
 {
-   fprintf(stderr, "Usage: odd [if=F1] [of=F2] [bsize] [skip=N] [count=N] 
[quiet] [nosync]
");
-   exit(EXIT_FAILURE);
+   eprintf("usage: %s [-h] [if=F1] [of=F2] [bsize] [skip=N] [count=N] 
[quiet] [nosync]
", argv0);
 }
 
 static void
@@ -223,6 +223,7 @@ main(int argc, char *argv[])
char buf[1024];
struct dd_config config;
 
+   argv0 = argv[0];
memset(&config, 0, sizeof(config));
config.bs = 1<<16;
config.in = "/dev/stdin";
@@ -251,6 +252,8 @@ main(int argc, char *argv[])
config.quiet = 1;
else if (strcmp(argv[i], "nosync") == 0)
config.nosync = 1;
+   else if (strcmp(argv[i], "-h") == 0)
+   usage();
}
 
if (!config.in || !config.out)
@@ -260,7 +263,7 @@ main(int argc, char *argv[])
signal(SIGINT, sig_int);
 
if (copy(&config) < 0)
-   fprintf(stderr, "Error: %s
", strerror(config.saved_errno));
+   eprintf("copy:");
print_stat(&config);
 
if (config.nosync == 0)




[hackers] [ubase] Ensure a proper exit code || sin

2014-06-04 Thread git
commit 144a89326822d55c65997a37ea048622ceb96020
Author: sin 
Date:   Wed Jun 4 13:02:07 2014 +0100

Ensure a proper exit code

If copy() fails at least print stats.

diff --git a/dd.c b/dd.c
index c4db974..9942253 100644
--- a/dd.c
+++ b/dd.c
@@ -263,10 +263,10 @@ main(int argc, char *argv[])
signal(SIGINT, sig_int);
 
if (copy(&config) < 0)
-   eprintf("copy:");
+   weprintf("copy:");
print_stat(&config);
 
if (config.nosync == 0)
sync(); sync();
-   return EXIT_SUCCESS;
+   return config.saved_errno;
 }




[hackers] [ubase] Use estrtoul() in dd(1) || sin

2014-06-04 Thread git
commit 6ea2b1aa53ec29d3cf9adc7c981bfa4a4c33f29b
Author: sin 
Date:   Wed Jun 4 13:07:34 2014 +0100

Use estrtoul() in dd(1)

Allow specifications in hex and octal as well.

diff --git a/Makefile b/Makefile
index 04fe64d..a68d3ce 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ LIB = \
util/ealloc.o \
util/eprintf.o\
util/estrtol.o\
+   util/estrtoul.o   \
util/explicit_bzero.o \
util/proc.o   \
util/putword.o\
diff --git a/dd.c b/dd.c
index 9942253..2685d54 100644
--- a/dd.c
+++ b/dd.c
@@ -237,15 +237,15 @@ main(int argc, char *argv[])
else if (sscanf(argv[i], "of=%1023c", buf) == 1)
config.out = strdup(buf);
else if (sscanf(argv[i], "skip=%1023c", buf) == 1)
-   config.skip = strtoul(buf, NULL, 10);
+   config.skip = estrtoul(buf, 0);
else if (sscanf(argv[i], "seek=%1023c", buf) == 1)
-   config.seek = strtoul(buf, NULL, 10);
+   config.seek = estrtoul(buf, 0);
else if (sscanf(argv[i], "count=%1023c", buf) == 1)
-   config.count = strtoul(buf, NULL, 10);
+   config.count = estrtoul(buf, 0);
else if (strcmp(argv[i], "direct") == 0)
config.direct = 1;
else if (sscanf(argv[i], "bs=%1023c", buf) == 1)
-   config.bs = strtoul(buf, NULL, 10);
+   config.bs = estrtoul(buf, 0);
else if (strcmp(argv[i], "bs") == 0)
config.bs = 0;
else if (strcmp(argv[i], "quiet") == 0)
diff --git a/util.h b/util.h
index 0ed7f6b..f43c6ee 100644
--- a/util.h
+++ b/util.h
@@ -27,6 +27,9 @@ char *estrdup(const char *);
 /* estrtol.c */
 long estrtol(const char *, int);
 
+/* estrtoul.c */
+unsigned long estrtoul(const char *, int);
+
 /* explicit_bzero.c */
 #undef explicit_bzero
 void explicit_bzero(void *, size_t);
diff --git a/util/estrtoul.c b/util/estrtoul.c
new file mode 100644
index 000..f56a720
--- /dev/null
+++ b/util/estrtoul.c
@@ -0,0 +1,26 @@
+/* See LICENSE file for copyright and license details. */
+#include 
+#include 
+#include 
+
+#include "../util.h"
+
+unsigned long
+estrtoul(const char *s, int base)
+{
+   char *end;
+   unsigned long n;
+
+   errno = 0;
+   n = strtoul(s, &end, base);
+   if(*end != '



[hackers] [ubase] Add dd to README and remove from TODO || sin

2014-06-04 Thread git
commit 4b58a3fcbedf1ed4420522ec549dd1d0af0f7fd2
Author: sin 
Date:   Wed Jun 4 13:11:16 2014 +0100

Add dd to README and remove from TODO

diff --git a/README b/README
index ac8d0ee..670ee6c 100644
--- a/README
+++ b/README
@@ -6,7 +6,7 @@ much simpler.
 
 The following programs are currently implemented:
 
-chvt clear  ctrlaltdel df  dmesg eject  fallocate free  getty halt
+chvt clear ctrlaltdel dd df  dmesg eject fallocate free getty halt
 hwclock id  insmod killall5 login  lsmod lsusb mknod  mkswap mount
 mountpoint  pagesize pidof  pivot_root  ps respawn  rmmod stat  su
 swapoff swapon  switch_root sysctl truncate umount  unshare uptime
diff --git a/TODO b/TODO
index 1645632..1b47500 100644
--- a/TODO
+++ b/TODO
@@ -14,6 +14,5 @@ Tools to be implemented
  * addgroup
  * rmuser
  * rmgroup
- * dd
  * ifconfig
  * hwclock




[hackers] [ubase] Use the macros from inttypes.h to properly print uint64_t || sin

2014-06-04 Thread git
commit a4e8cf6664d63b86349a776b19e2f5b21873e8b5
Author: sin 
Date:   Wed Jun 4 13:17:57 2014 +0100

Use the macros from inttypes.h to properly print uint64_t

diff --git a/dd.c b/dd.c
index 2685d54..994f712 100644
--- a/dd.c
+++ b/dd.c
@@ -8,6 +8,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -201,9 +202,12 @@ print_stat(const struct dd_config *ddc)
if (ddc->quiet)
return;
 
-   fprintf(stderr, "%lu records in
%lu records out
%lu bytes (%lu MB) copied, %lu s, %f MB/s [%f mB/s]
",
-   ddc->rec_in, ddc->rec_out, ddc->b_out, ddc->b_out/(1<<20),
-   ddc->t_end - ddc->t_start,
+   fprintf(stderr, "%"PRIu64" records in
", ddc->rec_in);
+   fprintf(stderr, "%"PRIu64" records out
", ddc->rec_out);
+   fprintf(stderr, "%"PRIu64" bytes (%"PRIu64" MB) copied", ddc->b_out,
+   ddc->b_out/(1<<20));
+   fprintf(stderr, ", %lu s, %f MB/s [%f mB/s]
",
+   (unsigned long)ddc->t_end - ddc->t_start,
((double)(ddc->b_out/(1<<20)))/(ddc->t_end - ddc->t_start),
((double)(ddc->b_out/(1000*1000)))/(ddc->t_end - ddc->t_start));
 }




[hackers] [ubase] ubase builds with clang as well || sin

2014-06-04 Thread git
commit ee5c4e45212bf8d3642be066a7495965f23616f4
Author: sin 
Date:   Wed Jun 4 13:31:48 2014 +0100

ubase builds with clang as well

diff --git a/README b/README
index 670ee6c..fae6dce 100644
--- a/README
+++ b/README
@@ -29,7 +29,7 @@ individual tools to ubase-box.
 Ideally you will  want to statically link ubase.   We highly recommend
 using musl-libc[2].
 
-ubase is known to compile with gcc and tcc.
+ubase is known to compile with gcc, clang and tcc.
 
 [1] http://git.suckless.org/sbase/
 [2] http://www.musl-libc.org/




[hackers] [ubase] Fallback to pagesize transfers in dd(1) || sin

2014-06-04 Thread git
commit 9c7d08773fcd398b50b484c5965438116cdb85e7
Author: sin 
Date:   Wed Jun 4 13:34:13 2014 +0100

Fallback to pagesize transfers in dd(1)

diff --git a/dd.c b/dd.c
index 994f712..79a3d08 100644
--- a/dd.c
+++ b/dd.c
@@ -41,6 +41,7 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
struct stat st;
int fli = O_RDONLY|O_LARGEFILE|O_NOCTTY, flo = 
O_WRONLY|O_LARGEFILE|O_NOATIME|O_NOCTTY;
uid_t euid = 0;
+   long pagesize;
 
if (ddc->direct) {
fli |= O_DIRECT;
@@ -68,14 +69,17 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
if (!ddc->bs) {
struct statfs fst;
memset(&fst, 0, sizeof(fst));
+   pagesize = sysconf(_SC_PAGESIZE);
+   if (pagesize <= 0)
+   pagesize = 0x1000;
if (statfs(ddc->out, &fst) < 0 || fst.f_bsize == 0)
-   fst.f_bsize = 0x1000;
+   fst.f_bsize = pagesize;
if ((unsigned long)fst.f_bsize > (unsigned long)st.st_blksize)
ddc->bs = fst.f_bsize;
else
ddc->bs = st.st_blksize;
if (ddc->bs == 0)
-   ddc->bs = 0x1000;
+   ddc->bs = pagesize;
}
 
/* check if device or regular file */




  1   2   3   4   5   6   7   8   9   10   >