Skip to content

Commit

Permalink
add memrchr, rawmemrchr, bump to 0.1.35
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhams committed Sep 23, 2020
1 parent 999730a commit eb614a8
Show file tree
Hide file tree
Showing 14 changed files with 832 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libdicl/configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ(2.65)
AC_INIT([libdicl],
[0.1.34],
[0.1.35],
[[email protected]])

AC_SUBST(ACLOCAL_AMFLAGS, "-I macros")
Expand Down
1 change: 1 addition & 0 deletions libdicl/gl/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
# getopt-posix \
# getprogname \
# memmem \
# memrchr \
# mkdtemp \
# mktime \
# nanosleep \
Expand Down
71 changes: 71 additions & 0 deletions libdicl/gl/closedir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Stop reading the entries of a directory.
Copyright (C) 2006-2019 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */

#include <config.h>

/* Specification. */
#include <dirent.h>

#if REPLACE_FCHDIR
# include <unistd.h>
#endif

#if HAVE_CLOSEDIR

/* Override closedir(), to keep track of the open file descriptors.
Needed because there is a function dirfd(). */

#else

# include <stdlib.h>

# include "dirent-private.h"

#endif

int
closedir (DIR *dirp)
{
# if REPLACE_FCHDIR || REPLACE_DIRFD
int fd = dirfd (dirp);
# endif
int retval;

#if HAVE_CLOSEDIR
# undef closedir

retval = closedir (dirp);

# ifdef __KLIBC__
if (!retval)
_gl_unregister_dirp_fd (fd);
# endif
#else

if (dirp->current != INVALID_HANDLE_VALUE)
FindClose (dirp->current);
free (dirp);

retval = 0;

#endif

#if REPLACE_FCHDIR
if (retval >= 0)
_gl_unregister_fd (fd);
#endif
return retval;
}
40 changes: 40 additions & 0 deletions libdicl/gl/dirent-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Private details of the DIR type.
Copyright (C) 2011-2019 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */

#ifndef _DIRENT_PRIVATE_H
#define _DIRENT_PRIVATE_H 1

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

struct gl_directory
{
/* Status, or error code to produce in next readdir() call.
-2 means the end of the directory is already reached,
-1 means the entry was already filled by FindFirstFile,
0 means the entry needs to be filled using FindNextFile.
A positive value is an error code. */
int status;
/* Handle, reading the directory, at current position. */
HANDLE current;
/* Found directory entry. */
WIN32_FIND_DATA entry;
/* Argument to pass to FindFirstFile. It consists of the absolutized
directory name, followed by a directory separator and the wildcards. */
char dir_name_mask[1];
};

#endif /* _DIRENT_PRIVATE_H */
88 changes: 88 additions & 0 deletions libdicl/gl/dup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* Duplicate an open file descriptor.
Copyright (C) 2011-2019 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */

#include <config.h>

/* Specification. */
#include <unistd.h>

#include <errno.h>

#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
# include "msvc-inval.h"
#endif

#undef dup

#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
static int
dup_nothrow (int fd)
{
int result;

TRY_MSVC_INVAL
{
result = dup (fd);
}
CATCH_MSVC_INVAL
{
result = -1;
errno = EBADF;
}
DONE_MSVC_INVAL;

return result;
}
#elif defined __KLIBC__
# include <fcntl.h>
# include <sys/stat.h>

# include <InnoTekLIBC/backend.h>

static int
dup_nothrow (int fd)
{
int dupfd;
struct stat sbuf;

dupfd = dup (fd);
if (dupfd == -1 && errno == ENOTSUP \
&& !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
{
char path[_MAX_PATH];

/* Get a path from fd */
if (!__libc_Back_ioFHToPath (fd, path, sizeof (path)))
dupfd = open (path, O_RDONLY);
}

return dupfd;
}
#else
# define dup_nothrow dup
#endif

int
rpl_dup (int fd)
{
int result = dup_nothrow (fd);
#if REPLACE_FCHDIR
if (result >= 0)
result = _gl_register_dup (fd, result);
#endif
return result;
}
Loading

0 comments on commit eb614a8

Please sign in to comment.