[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coreutils dirname int cleanup
From: |
Paul Eggert |
Subject: |
coreutils dirname int cleanup |
Date: |
Mon, 02 Aug 2004 10:36:41 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
I installed this minor code cleanup to the dirname module in
coreutils. The only visible change is that strip_trailing_slashes now
returns bool (1 vs 0), not int ('/' vs 0) but none of the callers care
about this.
2004-08-02 Paul Eggert <address@hidden>
* stripslash.c (strip_trailing_slashes): Now returns bool.
* dirname.h (strip_trailing_slashes): Likewise.
Include <stdbool.h>.
* dirname.c (dir_name): Use bool when appropriate.
Index: lib/dirname.h
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/dirname.h,v
retrieving revision 1.11
diff -p -u -r1.11 dirname.h
--- lib/dirname.h 30 Jun 2004 22:37:03 -0000 1.11
+++ lib/dirname.h 16 Jul 2004 20:44:08 -0000
@@ -19,6 +19,7 @@
#ifndef DIRNAME_H_
# define DIRNAME_H_ 1
+# include <stdbool.h>
# include <stddef.h>
# ifndef DIRECTORY_SEPARATOR
@@ -41,6 +42,6 @@ char *dir_name (char const *path);
size_t base_len (char const *path);
size_t dir_len (char const *path);
-int strip_trailing_slashes (char *path);
+bool strip_trailing_slashes (char *path);
#endif /* not DIRNAME_H_ */
Index: lib/dirname.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/dirname.c,v
retrieving revision 1.32
diff -p -u -r1.32 dirname.c
--- lib/dirname.c 30 Jun 2004 22:38:26 -0000 1.32
+++ lib/dirname.c 2 Aug 2004 17:30:33 -0000
@@ -53,7 +53,7 @@ char *
dir_name (char const *path)
{
size_t length = dir_len (path);
- int append_dot = (length == FILE_SYSTEM_PREFIX_LEN (path));
+ bool append_dot = (length == FILE_SYSTEM_PREFIX_LEN (path));
char *newpath = xmalloc (length + append_dot + 1);
memcpy (newpath, path, length);
if (append_dot)
Index: lib/stripslash.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/stripslash.c,v
retrieving revision 1.11
diff -p -u -r1.11 stripslash.c
--- lib/stripslash.c 10 Sep 2003 08:28:38 -0000 1.11
+++ lib/stripslash.c 2 Aug 2004 17:31:37 -0000
@@ -1,5 +1,5 @@
/* stripslash.c -- remove redundant trailing slashes from a file name
- Copyright (C) 1990, 2001, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1990, 2001, 2003, 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,18 +22,18 @@
#include "dirname.h"
/* Remove trailing slashes from PATH.
- Return nonzero if a trailing slash was removed.
+ Return true if a trailing slash was removed.
This is useful when using filename completion from a shell that
adds a "/" after directory names (such as tcsh and bash), because
the Unix rename and rmdir system calls return an "Invalid argument" error
when given a path that ends in "/" (except for the root directory). */
-int
+bool
strip_trailing_slashes (char *path)
{
char *base = base_name (path);
char *base_lim = base + base_len (base);
- int had_slash = *base_lim;
+ bool had_slash = (*base_lim != '\0');
*base_lim = '\0';
return had_slash;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- coreutils dirname int cleanup,
Paul Eggert <=