From: Jim Meyering Date: Sun, 31 Aug 2003 11:11:10 +0000 (+0000) Subject: (split_3): Accept the BSD format for generic X-Git-Tag: COREUTILS-5_0_91~75 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b1f0fa519f576eefb1eafd41e8a5fb3404cf763;p=platform%2Fupstream%2Fcoreutils.git (split_3): Accept the BSD format for generic message digest modes. Currently works with BSD's MD5 and SHA1 formats since these are the two algorithms presently used in coreutils. Updated comments to reflect this change. (bsd_split_3): Updated comments. --- diff --git a/src/md5sum.c b/src/md5sum.c index 2473020..c1685a5 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -161,9 +161,9 @@ text), and name for each FILE.\n"), #define ISWHITE(c) ((c) == ' ' || (c) == '\t') -/* Split the checksum string S (of length S_LEN) from a BSD 'md5' - command into two parts: a hexadecimal digest, and the file name. S - is modified. */ +/* Split the checksum string S (of length S_LEN) from a BSD 'md5' or + 'sha1' command into two parts: a hexadecimal digest, and the file + name. S is modified. */ static int bsd_split_3 (char *s, size_t s_len, unsigned char **hex_digest, char **file_name) @@ -172,8 +172,8 @@ bsd_split_3 (char *s, size_t s_len, unsigned char **hex_digest, char **file_name *file_name = s; - /* Find end of filename. The BSD 'md5' does not escape filenames, so - search backwards for the last ')'. */ + /* Find end of filename. The BSD 'md5' and 'sha1' commands do not escape + filenames, so search backwards for the last ')'. */ i = s_len - 1; while (i && s[i] != ')') i--; @@ -208,16 +208,23 @@ split_3 (char *s, size_t s_len, { size_t i; int escaped_filename = 0; + size_t algo_name_len; i = 0; while (ISWHITE (s[i])) ++i; /* Check for BSD-style checksum line. */ - if (algorithm == ALG_MD5 && strncmp (s + i, "MD5 (", 5) == 0) + algo_name_len = strlen (DIGEST_TYPE_STRING (algorithm)); + if (strncmp (s + i, DIGEST_TYPE_STRING (algorithm), algo_name_len) == 0) { - *binary = 0; - return bsd_split_3 (s + i + 5, s_len - i - 5, hex_digest, file_name); + if (strncmp (s + i + algo_name_len, " (", 2) == 0) + { + *binary = 0; + return bsd_split_3 (s + i + algo_name_len + 2, + s_len - (i + algo_name_len + 2), + hex_digest, file_name); + } } /* Ignore this line if it is too short.