cksum(1) patch

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

cksum(1) patch

Peter J. Philipp-2
Hi,

I did some research on different operating systems regarding checksumming and
found that solaris had a nice option called "digest -l" which prints the
available algorithms and exits.  I wrote this functionality into cksum(1)
that you can have if you want it.  Patch follows.

-peter


? cksum.1-orig
? cksum.patch
? md5.c-orig
Index: cksum.1
===================================================================
RCS file: /cvs/src/bin/md5/cksum.1,v
retrieving revision 1.19
diff -u -r1.19 cksum.1
--- cksum.1 8 Feb 2009 17:15:09 -0000 1.19
+++ cksum.1 11 May 2009 08:07:36 -0000
@@ -42,7 +42,7 @@
 .Sh SYNOPSIS
 .Nm cksum
 .Bk -words
-.Op Fl bpqrtx
+.Op Fl blpqrtx
 .Op Fl a Ar algorithms
 .Op Fl c Op Ar checklist ...
 .Op Fl o Ar 1 | 2
@@ -162,6 +162,8 @@
 option may not be used in conjunction with more than a single
 .Fl a
 option.
+.It Fl l
+outputs the algorithms available and exits.
 .It Fl o Ar 1 | 2
 Use historic algorithms instead of the (superior) default one
 (see below).
Index: md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.50
diff -u -r1.50 md5.c
--- md5.c 6 Sep 2008 12:01:34 -0000 1.50
+++ md5.c 11 May 2009 08:07:36 -0000
@@ -201,6 +201,7 @@
 void usage(void) __attribute__((__noreturn__));
 
 extern char *__progname;
+extern int errno;
 int qflag = 0;
 
 int
@@ -210,14 +211,14 @@
  struct hash_list hl;
  size_t len;
  char *cp, *input_string;
- int fl, error, base64;
+ int fl, error, base64, i;
  int bflag, cflag, pflag, rflag, tflag, xflag;
 
  static const char *optstr[5] = {
  "bcpqrs:tx",
  "bcpqrs:tx",
  "bcpqrs:tx",
- "a:bco:pqrs:tx",
+ "a:bco:lpqrs:tx",
  "a:bco:pqrs:tx"
  };
 
@@ -315,6 +316,20 @@
  if (hftmp == TAILQ_END(&hl))
  hash_insert(&hl, hf, 0);
  break;
+ case 'l':
+ for (hf = functions; hf->name != NULL; hf++) {
+ len = strlen(hf->name);
+ if ((cp = calloc(1, len + 1)) == NULL)
+ errx(1, "malloc: %s", strerror(errno));
+
+ for (i = 0; i < len; i++) {
+ cp[i] = tolower(*(hf->name + i));
+ }
+
+ printf("%s\n", cp);
+ free(cp);
+ }
+ exit(0);
  case 'p':
  pflag = 1;
  break;

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Hyjial Irldar
``man 1 cksum'' already does that for you.

2009/5/11 Peter J. Philipp <[hidden email]>:

> Hi,
>
> I did some research on different operating systems regarding checksumming and
> found that solaris had a nice option called "digest -l" which prints the
> available algorithms and exits. B I wrote this functionality into cksum(1)
> that you can have if you want it. B Patch follows.
>
> -peter
>
>
> ? cksum.1-orig
> ? cksum.patch
> ? md5.c-orig
> Index: cksum.1
> ===================================================================
> RCS file: /cvs/src/bin/md5/cksum.1,v
> retrieving revision 1.19
> diff -u -r1.19 cksum.1
> --- cksum.1 B  B  8 Feb 2009 17:15:09 -0000 B  B  B  1.19
> +++ cksum.1 B  B  11 May 2009 08:07:36 -0000
> @@ -42,7 +42,7 @@
> B .Sh SYNOPSIS
> B .Nm cksum
> B .Bk -words
> -.Op Fl bpqrtx
> +.Op Fl blpqrtx
> B .Op Fl a Ar algorithms
> B .Op Fl c Op Ar checklist ...
> B .Op Fl o Ar 1 | 2
> @@ -162,6 +162,8 @@
> B option may not be used in conjunction with more than a single
> B .Fl a
> B option.
> +.It Fl l
> +outputs the algorithms available and exits.
> B .It Fl o Ar 1 | 2
> B Use historic algorithms instead of the (superior) default one
> B (see below).
> Index: md5.c
> ===================================================================
> RCS file: /cvs/src/bin/md5/md5.c,v
> retrieving revision 1.50
> diff -u -r1.50 md5.c
> --- md5.c B  B  B  6 Sep 2008 12:01:34 -0000 B  B  B  1.50
> +++ md5.c B  B  B  11 May 2009 08:07:36 -0000
> @@ -201,6 +201,7 @@
> B void usage(void) __attribute__((__noreturn__));
>
> B extern char *__progname;
> +extern int errno;
> B int qflag = 0;
>
> B int
> @@ -210,14 +211,14 @@
> B  B  B  B struct hash_list hl;
> B  B  B  B size_t len;
> B  B  B  B char *cp, *input_string;
> - B  B  B  int fl, error, base64;
> + B  B  B  int fl, error, base64, i;
> B  B  B  B int bflag, cflag, pflag, rflag, tflag, xflag;
>
> B  B  B  B static const char *optstr[5] = {
> B  B  B  B  B  B  B  B "bcpqrs:tx",
> B  B  B  B  B  B  B  B "bcpqrs:tx",
> B  B  B  B  B  B  B  B "bcpqrs:tx",
> - B  B  B  B  B  B  B  "a:bco:pqrs:tx",
> + B  B  B  B  B  B  B  "a:bco:lpqrs:tx",
> B  B  B  B  B  B  B  B "a:bco:pqrs:tx"
> B  B  B  B };
>
> @@ -315,6 +316,20 @@
> B  B  B  B  B  B  B  B  B  B  B  B if (hftmp == TAILQ_END(&hl))
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B hash_insert(&hl, hf, 0);
> B  B  B  B  B  B  B  B  B  B  B  B break;
> + B  B  B  B  B  B  B  case 'l':
> + B  B  B  B  B  B  B  B  B  B  B  for (hf = functions; hf->name != NULL; hf++) {
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  len = strlen(hf->name);
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  if ((cp = calloc(1, len + 1)) == NULL)
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  errx(1, "malloc: %s", strerror(errno));
> +
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  for (i = 0; i < len; i++) {
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  cp[i] = tolower(*(hf->name + i));
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  }
> +
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  printf("%s\n", cp);
> + B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  free(cp);
> + B  B  B  B  B  B  B  B  B  B  B  }
> + B  B  B  B  B  B  B  B  B  B  B  exit(0);
> B  B  B  B  B  B  B  B case 'p':
> B  B  B  B  B  B  B  B  B  B  B  B pflag = 1;
> B  B  B  B  B  B  B  B  B  B  B  B break;

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Nick Guenther
On Tue, May 12, 2009 at 6:20 AM, Hyjial Irldar <[hidden email]> wrote:

>
> 2009/5/11 Peter J. Philipp <[hidden email]>:
>> Hi,
>>
>> I did some research on different operating systems regarding checksumming and
>> found that solaris had a nice option called "digest -l" which prints the
>> available algorithms and exits. B I wrote this functionality into cksum(1)
>> that you can have if you want it. B Patch follows.
>>
>
> ``man 1 cksum'' already does that for you.

Oh come, it's a decent patch; nice because it auto-documents code. It
might be a little trivial but there's no need to go out of your way to
be rude.

-Nick

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

David Coppa
On Wed, May 13, 2009 at 9:36 AM, Nick Guenther <[hidden email]> wrote:

> Oh come, it's a decent patch; nice because it auto-documents code. It
> might be a little trivial but there's no need to go out of your way to
> be rude.
>
> -Nick

FWIW, I like it and I'd like it to be committed.

cheers
-d

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Otto Moerbeek
In reply to this post by Peter J. Philipp-2
On Mon, May 11, 2009 at 10:16:25AM +0200, Peter J. Philipp wrote:

> Hi,
>
> I did some research on different operating systems regarding checksumming and
> found that solaris had a nice option called "digest -l" which prints the
> available algorithms and exits.  I wrote this functionality into cksum(1)
> that you can have if you want it.  Patch follows.
>
> -peter

I kinda like this, but comments inline.


> ? cksum.1-orig
> ? cksum.patch
> ? md5.c-orig
> Index: cksum.1
> ===================================================================
> RCS file: /cvs/src/bin/md5/cksum.1,v
> retrieving revision 1.19
> diff -u -r1.19 cksum.1
> --- cksum.1 8 Feb 2009 17:15:09 -0000 1.19
> +++ cksum.1 11 May 2009 08:07:36 -0000
> @@ -42,7 +42,7 @@
>  .Sh SYNOPSIS
>  .Nm cksum
>  .Bk -words
> -.Op Fl bpqrtx
> +.Op Fl blpqrtx
>  .Op Fl a Ar algorithms
>  .Op Fl c Op Ar checklist ...
>  .Op Fl o Ar 1 | 2
> @@ -162,6 +162,8 @@
>  option may not be used in conjunction with more than a single
>  .Fl a
>  option.
> +.It Fl l
> +outputs the algorithms available and exits.
>  .It Fl o Ar 1 | 2
>  Use historic algorithms instead of the (superior) default one
>  (see below).
> Index: md5.c
> ===================================================================
> RCS file: /cvs/src/bin/md5/md5.c,v
> retrieving revision 1.50
> diff -u -r1.50 md5.c
> --- md5.c 6 Sep 2008 12:01:34 -0000 1.50
> +++ md5.c 11 May 2009 08:07:36 -0000
> @@ -201,6 +201,7 @@
>  void usage(void) __attribute__((__noreturn__));
>  
>  extern char *__progname;
> +extern int errno;

Better include <errno.h>

>  int qflag = 0;
>  
>  int
> @@ -210,14 +211,14 @@
>   struct hash_list hl;
>   size_t len;
>   char *cp, *input_string;
> - int fl, error, base64;
> + int fl, error, base64, i;
>   int bflag, cflag, pflag, rflag, tflag, xflag;
>  
>   static const char *optstr[5] = {
>   "bcpqrs:tx",
>   "bcpqrs:tx",
>   "bcpqrs:tx",
> - "a:bco:pqrs:tx",
> + "a:bco:lpqrs:tx",
>   "a:bco:pqrs:tx"
>   };
>  
> @@ -315,6 +316,20 @@
>   if (hftmp == TAILQ_END(&hl))
>   hash_insert(&hl, hf, 0);
>   break;
> + case 'l':
> + for (hf = functions; hf->name != NULL; hf++) {
> + len = strlen(hf->name);
> + if ((cp = calloc(1, len + 1)) == NULL)
> + errx(1, "malloc: %s", strerror(errno));

better use
                                        err(1, "malloc");
it has the strerror call built in

> +
> + for (i = 0; i < len; i++) {
> + cp[i] = tolower(*(hf->name + i));

better use the same style for the lhs and rhs of the assigmnent. i.e.:

                                        cp[i] = tolower(hf->name[i]))
       
> + }
> +
> + printf("%s\n", cp);
> + free(cp);
> + }
> + exit(0);
>   case 'p':
>   pflag = 1;
>   break;


Come to think of it, why don't you just putchar(tolower(hf->name[i]))
in a loop? Saves you the calloc and error handling.

Also, don't forget to fix usage().

        -Otto

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Stuart Henderson
On 2009/05/13 10:40, Otto Moerbeek wrote:
> >
> > I did some research on different operating systems regarding checksumming and
> > found that solaris had a nice option called "digest -l" which prints the
> > available algorithms and exits.  I wrote this functionality into cksum(1)
> > that you can have if you want it.  Patch follows.
> >
> > -peter
>
> I kinda like this, but comments inline.

it might be nice to display the list of algorithms when an unsupported
algorithm is chosen, e.g.

$ cksum -a foo
cksum: unknown algorithm "foo", available algorithms:
cksum, md4, md5, rmd160, sha1, sha256, sha384, sha512, sum, sysvsum.
usage: cksum [-bpqrtx] [-a algorithms] [-c [checklist ...]] [-o 1 | 2]
             [-s string] [file ...]

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Peter J. Philipp-2
In reply to this post by Otto Moerbeek
On Wed, May 13, 2009 at 10:40:13AM +0200, Otto Moerbeek wrote:
> Come to think of it, why don't you just putchar(tolower(hf->name[i]))
> in a loop? Saves you the calloc and error handling.
>
> Also, don't forget to fix usage().
>
> -Otto

Yeah, thanks.  Well I got good and critical feedback and Otto's prodding was
good enough to make me rewrite this puny patch.  Gone are errno, calloc() and
in is the putchar().  I stayed away from adding sthen's idea, perhaps he can do
the patch for that.  Patch follows:


? cksum.1-orig
? cksum.patch
? md5.c-orig
Index: cksum.1
===================================================================
RCS file: /cvs/src/bin/md5/cksum.1,v
retrieving revision 1.19
diff -u -r1.19 cksum.1
--- cksum.1 8 Feb 2009 17:15:09 -0000 1.19
+++ cksum.1 13 May 2009 10:03:46 -0000
@@ -42,7 +42,7 @@
 .Sh SYNOPSIS
 .Nm cksum
 .Bk -words
-.Op Fl bpqrtx
+.Op Fl blpqrtx
 .Op Fl a Ar algorithms
 .Op Fl c Op Ar checklist ...
 .Op Fl o Ar 1 | 2
@@ -162,6 +162,8 @@
 option may not be used in conjunction with more than a single
 .Fl a
 option.
+.It Fl l
+outputs the algorithms available and exits.
 .It Fl o Ar 1 | 2
 Use historic algorithms instead of the (superior) default one
 (see below).
Index: md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.50
diff -u -r1.50 md5.c
--- md5.c 6 Sep 2008 12:01:34 -0000 1.50
+++ md5.c 13 May 2009 10:03:46 -0000
@@ -210,14 +210,14 @@
  struct hash_list hl;
  size_t len;
  char *cp, *input_string;
- int fl, error, base64;
+ int fl, error, base64, i;
  int bflag, cflag, pflag, rflag, tflag, xflag;
 
  static const char *optstr[5] = {
  "bcpqrs:tx",
  "bcpqrs:tx",
  "bcpqrs:tx",
- "a:bco:pqrs:tx",
+ "a:bco:lpqrs:tx",
  "a:bco:pqrs:tx"
  };
 
@@ -315,6 +315,15 @@
  if (hftmp == TAILQ_END(&hl))
  hash_insert(&hl, hf, 0);
  break;
+ case 'l':
+ for (hf = functions; hf->name != NULL; hf++) {
+ len = strlen(hf->name);
+ for (i = 0; i < len; i++) {
+ putchar(tolower(hf->name[i]));
+ }
+ putchar('\n');
+ }
+ exit(0);
  case 'p':
  pflag = 1;
  break;

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Otto Moerbeek
On Wed, May 13, 2009 at 12:11:35PM +0200, Peter J. Philipp wrote:

> On Wed, May 13, 2009 at 10:40:13AM +0200, Otto Moerbeek wrote:
> > Come to think of it, why don't you just putchar(tolower(hf->name[i]))
> > in a loop? Saves you the calloc and error handling.
> >
> > Also, don't forget to fix usage().
> >
> > -Otto
>
> Yeah, thanks.  Well I got good and critical feedback and Otto's prodding was
> good enough to make me rewrite this puny patch.  Gone are errno, calloc() and
> in is the putchar().  I stayed away from adding sthen's idea, perhaps he can do
> the patch for that.  Patch follows:

You forgot to fix usage(). Also, I think it makes sense to allow -l
for sum(1) too, so that both commands that take -a also take -l.

        -Otto
       

>
>
> ? cksum.1-orig
> ? cksum.patch
> ? md5.c-orig
> Index: cksum.1
> ===================================================================
> RCS file: /cvs/src/bin/md5/cksum.1,v
> retrieving revision 1.19
> diff -u -r1.19 cksum.1
> --- cksum.1 8 Feb 2009 17:15:09 -0000 1.19
> +++ cksum.1 13 May 2009 10:03:46 -0000
> @@ -42,7 +42,7 @@
>  .Sh SYNOPSIS
>  .Nm cksum
>  .Bk -words
> -.Op Fl bpqrtx
> +.Op Fl blpqrtx
>  .Op Fl a Ar algorithms
>  .Op Fl c Op Ar checklist ...
>  .Op Fl o Ar 1 | 2
> @@ -162,6 +162,8 @@
>  option may not be used in conjunction with more than a single
>  .Fl a
>  option.
> +.It Fl l
> +outputs the algorithms available and exits.
>  .It Fl o Ar 1 | 2
>  Use historic algorithms instead of the (superior) default one
>  (see below).
> Index: md5.c
> ===================================================================
> RCS file: /cvs/src/bin/md5/md5.c,v
> retrieving revision 1.50
> diff -u -r1.50 md5.c
> --- md5.c 6 Sep 2008 12:01:34 -0000 1.50
> +++ md5.c 13 May 2009 10:03:46 -0000
> @@ -210,14 +210,14 @@
>   struct hash_list hl;
>   size_t len;
>   char *cp, *input_string;
> - int fl, error, base64;
> + int fl, error, base64, i;
>   int bflag, cflag, pflag, rflag, tflag, xflag;
>  
>   static const char *optstr[5] = {
>   "bcpqrs:tx",
>   "bcpqrs:tx",
>   "bcpqrs:tx",
> - "a:bco:pqrs:tx",
> + "a:bco:lpqrs:tx",
>   "a:bco:pqrs:tx"
>   };
>  
> @@ -315,6 +315,15 @@
>   if (hftmp == TAILQ_END(&hl))
>   hash_insert(&hl, hf, 0);
>   break;
> + case 'l':
> + for (hf = functions; hf->name != NULL; hf++) {
> + len = strlen(hf->name);
> + for (i = 0; i < len; i++) {
> + putchar(tolower(hf->name[i]));
> + }
> + putchar('\n');
> + }
> + exit(0);
>   case 'p':
>   pflag = 1;
>   break;

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Peter J. Philipp-2
On Wed, May 13, 2009 at 12:20:44PM +0200, Otto Moerbeek wrote:
> You forgot to fix usage(). Also, I think it makes sense to allow -l
> for sum(1) too, so that both commands that take -a also take -l.
>
> -Otto

Eeek.  Ok this will do then:

Regards,
-p


? cksum.1-orig
? cksum.patch
? md5.c-orig
Index: cksum.1
===================================================================
RCS file: /cvs/src/bin/md5/cksum.1,v
retrieving revision 1.19
diff -u -r1.19 cksum.1
--- cksum.1 8 Feb 2009 17:15:09 -0000 1.19
+++ cksum.1 13 May 2009 11:27:53 -0000
@@ -42,7 +42,7 @@
 .Sh SYNOPSIS
 .Nm cksum
 .Bk -words
-.Op Fl bpqrtx
+.Op Fl blpqrtx
 .Op Fl a Ar algorithms
 .Op Fl c Op Ar checklist ...
 .Op Fl o Ar 1 | 2
@@ -50,7 +50,7 @@
 .Op Ar file ...
 .Ek
 .Nm sum
-.Op Fl bpqrtx
+.Op Fl blpqrtx
 .Op Fl a Ar algorithms
 .Op Fl c Op Ar checklist ...
 .Op Fl o Ar 1 | 2
@@ -162,6 +162,8 @@
 option may not be used in conjunction with more than a single
 .Fl a
 option.
+.It Fl l
+outputs the algorithms available and exits.
 .It Fl o Ar 1 | 2
 Use historic algorithms instead of the (superior) default one
 (see below).
Index: md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.50
diff -u -r1.50 md5.c
--- md5.c 6 Sep 2008 12:01:34 -0000 1.50
+++ md5.c 13 May 2009 11:27:53 -0000
@@ -210,15 +210,15 @@
  struct hash_list hl;
  size_t len;
  char *cp, *input_string;
- int fl, error, base64;
+ int fl, error, base64, i;
  int bflag, cflag, pflag, rflag, tflag, xflag;
 
  static const char *optstr[5] = {
  "bcpqrs:tx",
  "bcpqrs:tx",
  "bcpqrs:tx",
- "a:bco:pqrs:tx",
- "a:bco:pqrs:tx"
+ "a:bco:lpqrs:tx",
+ "a:bco:lpqrs:tx"
  };
 
  TAILQ_INIT(&hl);
@@ -315,6 +315,15 @@
  if (hftmp == TAILQ_END(&hl))
  hash_insert(&hl, hf, 0);
  break;
+ case 'l':
+ for (hf = functions; hf->name != NULL; hf++) {
+ len = strlen(hf->name);
+ for (i = 0; i < len; i++) {
+ putchar(tolower(hf->name[i]));
+ }
+ putchar('\n');
+ }
+ exit(0);
  case 'p':
  pflag = 1;
  break;
@@ -794,7 +803,7 @@
  break;
  case MODE_CKSUM:
  case MODE_SUM:
- fprintf(stderr, "usage: %s [-bpqrtx] [-a algorithms] "
+ fprintf(stderr, "usage: %s [-blpqrtx] [-a algorithms] "
     "[-c [checklist ...]] [-o 1 | 2]\n"
     "       %*s [-s string] [file ...]\n",
     __progname, (int)strlen(__progname), "");

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Mark Kettenis
In reply to this post by Otto Moerbeek
> Date: Wed, 13 May 2009 12:20:44 +0200
> From: Otto Moerbeek <[hidden email]>
>
> On Wed, May 13, 2009 at 12:11:35PM +0200, Peter J. Philipp wrote:
>
> > On Wed, May 13, 2009 at 10:40:13AM +0200, Otto Moerbeek wrote:
> > > Come to think of it, why don't you just putchar(tolower(hf->name[i]))
> > > in a loop? Saves you the calloc and error handling.
> > >
> > > Also, don't forget to fix usage().
> > >
> > > -Otto
> >
> > Yeah, thanks.  Well I got good and critical feedback and Otto's prodding was
> > good enough to make me rewrite this puny patch.  Gone are errno, calloc() and
> > in is the putchar().  I stayed away from adding sthen's idea, perhaps he can do
> > the patch for that.  Patch follows:
>
> You forgot to fix usage(). Also, I think it makes sense to allow -l
> for sum(1) too, so that both commands that take -a also take -l.

That may be true, but I'm fairly certain that we will not add the -l
option to either cksum(1) or sum(1).  It's not defined by POSIX, nor
is it commonly available on other Unix-like systems.  Our goal is to
not introduce non-standard options since people will start using them
in scripts that will become unportable.

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Otto Moerbeek
On Wed, May 13, 2009 at 02:16:49PM +0200, Mark Kettenis wrote:

> > Date: Wed, 13 May 2009 12:20:44 +0200
> > From: Otto Moerbeek <[hidden email]>
> >
> > On Wed, May 13, 2009 at 12:11:35PM +0200, Peter J. Philipp wrote:
> >
> > > On Wed, May 13, 2009 at 10:40:13AM +0200, Otto Moerbeek wrote:
> > > > Come to think of it, why don't you just putchar(tolower(hf->name[i]))
> > > > in a loop? Saves you the calloc and error handling.
> > > >
> > > > Also, don't forget to fix usage().
> > > >
> > > > -Otto
> > >
> > > Yeah, thanks.  Well I got good and critical feedback and Otto's prodding was
> > > good enough to make me rewrite this puny patch.  Gone are errno, calloc() and
> > > in is the putchar().  I stayed away from adding sthen's idea, perhaps he can do
> > > the patch for that.  Patch follows:
> >
> > You forgot to fix usage(). Also, I think it makes sense to allow -l
> > for sum(1) too, so that both commands that take -a also take -l.
>
> That may be true, but I'm fairly certain that we will not add the -l
> option to either cksum(1) or sum(1).  It's not defined by POSIX, nor
> is it commonly available on other Unix-like systems.  Our goal is to
> not introduce non-standard options since people will start using them
> in scripts that will become unportable.

in the case of sum(1) and chsum(1) we aready deviate a lot. Posix does
not define any options for cksum(1) and does not define sum(1) at all.
We accept about a dozen options to both.

And I seem to remember the diff was inspired by Solaris.

        -Otto

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Mark Kettenis
> Date: Wed, 13 May 2009 14:28:06 +0200
> From: Otto Moerbeek <[hidden email]>
>
> On Wed, May 13, 2009 at 02:16:49PM +0200, Mark Kettenis wrote:
>
> > > Date: Wed, 13 May 2009 12:20:44 +0200
> > > From: Otto Moerbeek <[hidden email]>
> > >
> > > On Wed, May 13, 2009 at 12:11:35PM +0200, Peter J. Philipp wrote:
> > >
> > > > On Wed, May 13, 2009 at 10:40:13AM +0200, Otto Moerbeek wrote:
> > > > > Come to think of it, why don't you just putchar(tolower(hf->name[i]))
> > > > > in a loop? Saves you the calloc and error handling.
> > > > >
> > > > > Also, don't forget to fix usage().
> > > > >
> > > > > -Otto
> > > >
> > > > Yeah, thanks.  Well I got good and critical feedback and Otto's prodding was
> > > > good enough to make me rewrite this puny patch.  Gone are errno, calloc() and
> > > > in is the putchar().  I stayed away from adding sthen's idea, perhaps he can do
> > > > the patch for that.  Patch follows:
> > >
> > > You forgot to fix usage(). Also, I think it makes sense to allow -l
> > > for sum(1) too, so that both commands that take -a also take -l.
> >
> > That may be true, but I'm fairly certain that we will not add the -l
> > option to either cksum(1) or sum(1).  It's not defined by POSIX, nor
> > is it commonly available on other Unix-like systems.  Our goal is to
> > not introduce non-standard options since people will start using them
> > in scripts that will become unportable.
>
> in the case of sum(1) and chsum(1) we aready deviate a lot. Posix does
> not define any options for cksum(1) and does not define sum(1) at all.
> We accept about a dozen options to both.

I'm afraid, that's not an excuse for adding even more options.

> And I seem to remember the diff was inspired by Solaris.

$ uname -a
SunOS foo 5.10 Generic_127128-11 i86pc i386 i86pc
$ cksum -l
cksum: illegal option -- l
Usage: cksum [file ...]

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Peter J. Philipp-2
> > And I seem to remember the diff was inspired by Solaris.
>
> $ uname -a
> SunOS foo 5.10 Generic_127128-11 i86pc i386 i86pc
> $ cksum -l
> cksum: illegal option -- l
> Usage: cksum [file ...]

It was inspired by digest(1) not cksum.

sycorax$ uname -a
SunOS sycorax 5.10 Generic_137138-09 i86pc i386 i86pc
sycorax$ digest -l
sha1
md5
sha256
sha384
sha512
sycorax$

Regards,

-peter

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Otto Moerbeek
In reply to this post by Mark Kettenis
On Wed, May 13, 2009 at 03:18:05PM +0200, Mark Kettenis wrote:

> > Date: Wed, 13 May 2009 14:28:06 +0200
> > From: Otto Moerbeek <[hidden email]>
> >
> > On Wed, May 13, 2009 at 02:16:49PM +0200, Mark Kettenis wrote:
> >
> > > > Date: Wed, 13 May 2009 12:20:44 +0200
> > > > From: Otto Moerbeek <[hidden email]>
> > > >
> > > > On Wed, May 13, 2009 at 12:11:35PM +0200, Peter J. Philipp wrote:
> > > >
> > > > > On Wed, May 13, 2009 at 10:40:13AM +0200, Otto Moerbeek wrote:
> > > > > > Come to think of it, why don't you just putchar(tolower(hf->name[i]))
> > > > > > in a loop? Saves you the calloc and error handling.
> > > > > >
> > > > > > Also, don't forget to fix usage().
> > > > > >
> > > > > > -Otto
> > > > >
> > > > > Yeah, thanks.  Well I got good and critical feedback and Otto's prodding was
> > > > > good enough to make me rewrite this puny patch.  Gone are errno, calloc() and
> > > > > in is the putchar().  I stayed away from adding sthen's idea, perhaps he can do
> > > > > the patch for that.  Patch follows:
> > > >
> > > > You forgot to fix usage(). Also, I think it makes sense to allow -l
> > > > for sum(1) too, so that both commands that take -a also take -l.
> > >
> > > That may be true, but I'm fairly certain that we will not add the -l
> > > option to either cksum(1) or sum(1).  It's not defined by POSIX, nor
> > > is it commonly available on other Unix-like systems.  Our goal is to
> > > not introduce non-standard options since people will start using them
> > > in scripts that will become unportable.
> >
> > in the case of sum(1) and chsum(1) we aready deviate a lot. Posix does
> > not define any options for cksum(1) and does not define sum(1) at all.
> > We accept about a dozen options to both.
>
> I'm afraid, that's not an excuse for adding even more options.
>
> > And I seem to remember the diff was inspired by Solaris.
>
> $ uname -a
> SunOS foo 5.10 Generic_127128-11 i86pc i386 i86pc
> $ cksum -l
> cksum: illegal option -- l
> Usage: cksum [file ...]

It was the digest(1) command on solaris, i remembered that wrong.

Anyway, my point is that the cksum(1) already has a bunch of options
but also an obviously missing one. But an alternative would be to do what
sthen suggested and put the algorithm list into the usage and only
that.

        -Otto

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Jacek Masiulaniec-2
On Wed, May 13, 2009 at 03:28:04PM +0200, Otto Moerbeek wrote:
> Anyway, my point is that the cksum(1) already has a bunch of options
> but also an obviously missing one. But an alternative would be to do what
> sthen suggested and put the algorithm list into the usage and only
> that.

I like this.

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Theo de Raadt
In reply to this post by Stuart Henderson
> On 2009/05/13 10:40, Otto Moerbeek wrote:
> > >
> > > I did some research on different operating systems regarding checksumming and
> > > found that solaris had a nice option called "digest -l" which prints the
> > > available algorithms and exits.  I wrote this functionality into cksum(1)
> > > that you can have if you want it.  Patch follows.
> > >
> > > -peter
> >
> > I kinda like this, but comments inline.
>
> it might be nice to display the list of algorithms when an unsupported
> algorithm is chosen, e.g.
>
> $ cksum -a foo
> cksum: unknown algorithm "foo", available algorithms:
> cksum, md4, md5, rmd160, sha1, sha256, sha384, sha512, sum, sysvsum.
> usage: cksum [-bpqrtx] [-a algorithms] [-c [checklist ...]] [-o 1 | 2]
>              [-s string] [file ...]

I don't see why that is neccessary.

Who is that for?

Is it for the people who didn't install the manual set, or for the people
who don't want to read the manuals?

Reply | Threaded
Open this post in threaded view
|

Re: cksum(1) patch

Stuart Henderson
On 2009/05/13 09:26, Theo de Raadt wrote:

> > On 2009/05/13 10:40, Otto Moerbeek wrote:
> > > >
> > > > I did some research on different operating systems regarding checksumming and
> > > > found that solaris had a nice option called "digest -l" which prints the
> > > > available algorithms and exits.  I wrote this functionality into cksum(1)
> > > > that you can have if you want it.  Patch follows.
> > > >
> > > > -peter
> > >
> > > I kinda like this, but comments inline.
> >
> > it might be nice to display the list of algorithms when an unsupported
> > algorithm is chosen, e.g.
> >
> > $ cksum -a foo
> > cksum: unknown algorithm "foo", available algorithms:
> > cksum, md4, md5, rmd160, sha1, sha256, sha384, sha512, sum, sysvsum.
> > usage: cksum [-bpqrtx] [-a algorithms] [-c [checklist ...]] [-o 1 | 2]
> >              [-s string] [file ...]
>
> I don't see why that is neccessary.
>
> Who is that for?
>
> Is it for the people who didn't install the manual set, or for the people
> who don't want to read the manuals?

The manual suggests there might be others.

             Supported algorithms include cksum, md4, md5, rmd160, sha1,
             sha256, sha384, sha512, sum, and sysvsum.

How about s/include/are/?