From 2bf846b04cd044e11dc71bd2717b53468bf9d6ad Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 4 Sep 2014 18:07:37 +0100 Subject: [PATCH] Move LGPL parts of dbus-sysdeps-util-win.c into a separate file --- COPYING | 7 +- cmake/dbus/CMakeLists.txt | 4 + dbus/Makefile.am | 2 + dbus/dbus-sysdeps-util-dirent-win.c | 135 ++++++++++++++++++++++++++++++++++ dbus/dbus-sysdeps-util-dirent-win.h | 43 +++++++++++ dbus/dbus-sysdeps-util-win.c | 143 +----------------------------------- 6 files changed, 188 insertions(+), 146 deletions(-) create mode 100644 dbus/dbus-sysdeps-util-dirent-win.c create mode 100644 dbus/dbus-sysdeps-util-dirent-win.h diff --git a/COPYING b/COPYING index 4ab4a5a..9934beb 100644 --- a/COPYING +++ b/COPYING @@ -6,10 +6,9 @@ version). Both licenses are included here. Some of the standalone binaries are under the GPL only; in particular, but not limited to, tools/dbus-cleanup-sockets.c and test/decode-gcov.c. -dbus-sysdeps-util-win.c is effectively under the GPL only, because -it contains GPL-compatible but non-AFL code derived from kdelibs. -This means that when compiled for Windows, additional binaries, notably -including dbus-daemon.exe, are under the GPL only. +dbus-sysdeps-util-dirent-win.c is under the GNU Lesser General Public +License. This means that when compiled for Windows, additional binaries, +notably including dbus-daemon.exe, are effectively under the GPL only. Each source code file is marked with the proper copyright information - if you find a file that isn't marked please bring it to our attention. diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index a6aaba0..f537542 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -198,6 +198,10 @@ if (WIN32) set (DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} ${DBUS_DIR}/dbus-spawn-win.c ${DBUS_DIR}/dbus-sysdeps-util-win.c + ${DBUS_DIR}/dbus-sysdeps-util-dirent-win.c + ) + set (DBUS_UTIL_HEADERS ${DBUS_UTIL_HEADERS} + ${DBUS_DIR}/dbus-sysdeps-util-dirent-win.h ) if(WINCE) set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 442fd27..5a32745 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -78,6 +78,8 @@ DBUS_SHARED_arch_sources = \ DBUS_UTIL_arch_sources = \ dbus-sysdeps-util-win.c \ + dbus-sysdeps-util-dirent-win.h \ + dbus-sysdeps-util-dirent-win.c \ dbus-spawn-win.c else diff --git a/dbus/dbus-sysdeps-util-dirent-win.c b/dbus/dbus-sysdeps-util-dirent-win.c new file mode 100644 index 0000000..c3fee74 --- /dev/null +++ b/dbus/dbus-sysdeps-util-dirent-win.c @@ -0,0 +1,135 @@ +/* This file is part of the KDE project +Copyright (C) 2000 Werner Almesberger + +libc/sys/linux/sys/dirent.h - Directory entry as returned by readdir + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this program; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#include + +#include + +#include + +#define HAVE_NO_D_NAMLEN /* no struct dirent->d_namlen */ +#define HAVE_DD_LOCK /* have locking mechanism */ + +#define MAXNAMLEN 255 /* sizeof(struct dirent.d_name)-1 */ + +#define __dirfd(dir) (dir)->dd_fd + +/* typedef DIR - not the same as Unix */ +struct DBusEmulatedDIR + { + HANDLE handle; /* FindFirst/FindNext handle */ + short offset; /* offset into directory */ + short finished; /* 1 if there are not more files */ + WIN32_FIND_DATAA fileinfo; /* from FindFirst/FindNext */ + char *dir; /* the dir we are reading */ + struct dirent dent; /* the dirent to return */ + }; + +/********************************************************************** +* Implement dirent-style opendir/readdir/closedir on Window 95/NT +* +* Functions defined are opendir(), readdir() and closedir() with the +* same prototypes as the normal dirent.h implementation. +* +* Does not implement telldir(), seekdir(), rewinddir() or scandir(). +* The dirent struct is compatible with Unix, except that d_ino is +* always 1 and d_off is made up as we go along. +* +* Error codes are not available with errno but GetLastError. +* +* The DIR typedef is not compatible with Unix. +**********************************************************************/ + +DIR * _dbus_opendir(const char *dir) +{ + DIR *dp; + char *filespec; + HANDLE handle; + int index; + + filespec = malloc(strlen(dir) + 2 + 1); + strcpy(filespec, dir); + index = strlen(filespec) - 1; + if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\')) + filespec[index] = '\0'; + strcat(filespec, "\\*"); + + dp = (DIR *)malloc(sizeof(DIR)); + dp->offset = 0; + dp->finished = 0; + dp->dir = strdup(dir); + + handle = FindFirstFileA(filespec, &(dp->fileinfo)); + if (handle == INVALID_HANDLE_VALUE) + { + if (GetLastError() == ERROR_NO_MORE_FILES) + dp->finished = 1; + else + return NULL; + } + + dp->handle = handle; + free(filespec); + + return dp; +} + +struct dirent * _dbus_readdir(DIR *dp) +{ + int saved_err = GetLastError(); + + if (!dp || dp->finished) + return NULL; + + if (dp->offset != 0) + { + if (FindNextFileA(dp->handle, &(dp->fileinfo)) == 0) + { + if (GetLastError() == ERROR_NO_MORE_FILES) + { + SetLastError(saved_err); + dp->finished = 1; + } + return NULL; + } + } + dp->offset++; + + strncpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME); + dp->dent.d_ino = 1; + dp->dent.d_reclen = strlen(dp->dent.d_name); + dp->dent.d_off = dp->offset; + + return &(dp->dent); +} + +int _dbus_closedir(DIR *dp) +{ + if (!dp) + return 0; + FindClose(dp->handle); + if (dp->dir) + free(dp->dir); + if (dp) + free(dp); + + return 0; +} diff --git a/dbus/dbus-sysdeps-util-dirent-win.h b/dbus/dbus-sysdeps-util-dirent-win.h new file mode 100644 index 0000000..2f49da9 --- /dev/null +++ b/dbus/dbus-sysdeps-util-dirent-win.h @@ -0,0 +1,43 @@ +/* This file is part of the KDE project +Copyright (C) 2000 Werner Almesberger + +libc/sys/linux/sys/dirent.h - Directory entry as returned by readdir + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this program; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#ifndef DBUS_SYSDEPS_UTIL_DIRENT_WIN_H +#define DBUS_SYSDEPS_UTIL_DIRENT_WIN_H + +#include +#include + +typedef struct DBusEmulatedDIR DIR; + +/* struct dirent - same as Unix */ +struct dirent + { + long d_ino; /* inode (always 1 in WIN32) */ + off_t d_off; /* offset to this dirent */ + unsigned short d_reclen; /* length of d_name */ + char d_name[_MAX_FNAME+1]; /* filename (null terminated) */ + }; + +DIR * _dbus_opendir(const char *dir); +struct dirent * _dbus_readdir(DIR *dp); +int _dbus_closedir(DIR *dp); + +#endif diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index 4678b11..1b70f20 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -32,6 +32,7 @@ #include "dbus-string.h" #include "dbus-sysdeps.h" #include "dbus-sysdeps-win.h" +#include "dbus-sysdeps-util-dirent-win.h" #include "dbus-sockets-win.h" #include "dbus-memory.h" #include "dbus-pipe.h" @@ -424,148 +425,6 @@ _dbus_stat(const DBusString *filename, return TRUE; } - -/* This file is part of the KDE project -Copyright (C) 2000 Werner Almesberger - -libc/sys/linux/sys/dirent.h - Directory entry as returned by readdir - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public License -along with this program; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. -*/ -#define HAVE_NO_D_NAMLEN /* no struct dirent->d_namlen */ -#define HAVE_DD_LOCK /* have locking mechanism */ - -#define MAXNAMLEN 255 /* sizeof(struct dirent.d_name)-1 */ - -#define __dirfd(dir) (dir)->dd_fd - -/* struct dirent - same as Unix */ -struct dirent - { - long d_ino; /* inode (always 1 in WIN32) */ - off_t d_off; /* offset to this dirent */ - unsigned short d_reclen; /* length of d_name */ - char d_name[_MAX_FNAME+1]; /* filename (null terminated) */ - }; - -/* typedef DIR - not the same as Unix */ -typedef struct - { - HANDLE handle; /* FindFirst/FindNext handle */ - short offset; /* offset into directory */ - short finished; /* 1 if there are not more files */ - WIN32_FIND_DATAA fileinfo; /* from FindFirst/FindNext */ - char *dir; /* the dir we are reading */ - struct dirent dent; /* the dirent to return */ - } -DIR; - -/********************************************************************** -* Implement dirent-style opendir/readdir/closedir on Window 95/NT -* -* Functions defined are opendir(), readdir() and closedir() with the -* same prototypes as the normal dirent.h implementation. -* -* Does not implement telldir(), seekdir(), rewinddir() or scandir(). -* The dirent struct is compatible with Unix, except that d_ino is -* always 1 and d_off is made up as we go along. -* -* Error codes are not available with errno but GetLastError. -* -* The DIR typedef is not compatible with Unix. -**********************************************************************/ - -static DIR * _dbus_opendir(const char *dir) -{ - DIR *dp; - char *filespec; - HANDLE handle; - int index; - - filespec = malloc(strlen(dir) + 2 + 1); - strcpy(filespec, dir); - index = strlen(filespec) - 1; - if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\')) - filespec[index] = '\0'; - strcat(filespec, "\\*"); - - dp = (DIR *)malloc(sizeof(DIR)); - dp->offset = 0; - dp->finished = 0; - dp->dir = strdup(dir); - - handle = FindFirstFileA(filespec, &(dp->fileinfo)); - if (handle == INVALID_HANDLE_VALUE) - { - if (GetLastError() == ERROR_NO_MORE_FILES) - dp->finished = 1; - else - return NULL; - } - - dp->handle = handle; - free(filespec); - - return dp; -} - -static struct dirent * _dbus_readdir(DIR *dp) -{ - int saved_err = GetLastError(); - - if (!dp || dp->finished) - return NULL; - - if (dp->offset != 0) - { - if (FindNextFileA(dp->handle, &(dp->fileinfo)) == 0) - { - if (GetLastError() == ERROR_NO_MORE_FILES) - { - SetLastError(saved_err); - dp->finished = 1; - } - return NULL; - } - } - dp->offset++; - - strncpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME); - dp->dent.d_ino = 1; - dp->dent.d_reclen = strlen(dp->dent.d_name); - dp->dent.d_off = dp->offset; - - return &(dp->dent); -} - - -static int _dbus_closedir(DIR *dp) -{ - if (!dp) - return 0; - FindClose(dp->handle); - if (dp->dir) - free(dp->dir); - if (dp) - free(dp); - - return 0; -} - - /** * Internals of directory iterator */ -- 2.1.0