[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
new function fdsavedir (needed for GNU tar)
From: |
Paul Eggert |
Subject: |
new function fdsavedir (needed for GNU tar) |
Date: |
Tue, 29 Nov 2005 10:49:14 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
I installed the following patch to add new functionality to the
savedir module. I suspect the major change for other programs is that
savedir now depends on openat.
2005-11-29 Paul Eggert <address@hidden>
* modules/savedir (Depends-on): Add openat.
* lib/savedir.h (fdsavedir): New decl.
* lib/savedir.c (fdsavedir, savedirstream): New functions; the latter
contains most of the former guts of savedir.
(savedir): Use savedirstream.
Include "openat.h".
Index: lib/savedir.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/savedir.c,v
retrieving revision 1.27
diff -p -u -r1.27 savedir.c
--- lib/savedir.c 28 Oct 2005 23:02:35 -0000 1.27
+++ lib/savedir.c 29 Nov 2005 18:46:12 -0000
@@ -55,27 +55,27 @@
#include <stdlib.h>
#include <string.h>
+#include "openat.h"
#include "xalloc.h"
-/* Return a freshly allocated string containing the file names
- in directory DIR, separated by '\0' characters;
- the end is marked by two '\0' characters in a row.
- Return NULL (setting errno) if DIR cannot be opened, read, or closed. */
-
#ifndef NAME_SIZE_DEFAULT
# define NAME_SIZE_DEFAULT 512
#endif
-char *
-savedir (const char *dir)
+/* Return a freshly allocated string containing the file names
+ in directory DIRP, separated by '\0' characters;
+ the end is marked by two '\0' characters in a row.
+ Return NULL (setting errno) if DIRP cannot be read or closed.
+ If DIRP is NULL, return NULL without affecting errno. */
+
+static char *
+savedirstream (DIR *dirp)
{
- DIR *dirp;
char *name_space;
size_t allocated = NAME_SIZE_DEFAULT;
size_t used = 0;
int save_errno;
- dirp = opendir (dir);
if (dirp == NULL)
return NULL;
@@ -126,4 +126,26 @@ savedir (const char *dir)
return NULL;
}
return name_space;
+}
+
+/* Return a freshly allocated string containing the file names
+ in directory DIR, separated by '\0' characters;
+ the end is marked by two '\0' characters in a row.
+ Return NULL (setting errno) if DIR cannot be opened, read, or closed. */
+
+char *
+savedir (char const *dir)
+{
+ return savedirstream (opendir (dir));
+}
+
+/* Return a freshly allocated string containing the file names
+ in directory FD, separated by '\0' characters;
+ the end is marked by two '\0' characters in a row.
+ Return NULL (setting errno) if FD cannot be read or closed. */
+
+char *
+fdsavedir (int fd)
+{
+ return savedirstream (fdopendir (fd));
}
Index: lib/savedir.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/savedir.h,v
retrieving revision 1.7
diff -p -u -r1.7 savedir.h
--- lib/savedir.h 14 May 2005 06:03:58 -0000 1.7
+++ lib/savedir.h 29 Nov 2005 18:46:12 -0000
@@ -1,6 +1,6 @@
/* Save the list of files in a directory in a string.
- Copyright 1997, 1999, 2001, 2003 Free Software Foundation, Inc.
+ Copyright 1997, 1999, 2001, 2003, 2005 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
@@ -21,6 +21,7 @@
#if !defined SAVEDIR_H_
# define SAVEDIR_H_
-char *savedir (const char *dir);
+char *savedir (char const *dir);
+char *fdsavedir (int fd);
#endif
Index: modules/savedir
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/savedir,v
retrieving revision 1.5
diff -p -u -r1.5 savedir
--- modules/savedir 21 Mar 2005 22:07:25 -0000 1.5
+++ modules/savedir 29 Nov 2005 18:46:12 -0000
@@ -7,6 +7,7 @@ lib/savedir.c
m4/savedir.m4
Depends-on:
+openat
xalloc
configure.ac:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- new function fdsavedir (needed for GNU tar),
Paul Eggert <=