mirror of
https://github.com/transmission/transmission
synced 2025-03-12 07:03:44 +00:00
Adds basename/dirname implementation for platforms that lack it (BeOS...)
This commit is contained in:
parent
043ba9e1bf
commit
26b837ffc0
7 changed files with 168 additions and 2 deletions
|
@ -1475,6 +1475,7 @@
|
||||||
"-D__TRANSMISSION__",
|
"-D__TRANSMISSION__",
|
||||||
"-DHAVE_STRLCPY",
|
"-DHAVE_STRLCPY",
|
||||||
"-DHAVE_STRLCAT",
|
"-DHAVE_STRLCAT",
|
||||||
|
"-DHAVE_LIBGEN",
|
||||||
);
|
);
|
||||||
PRODUCT_NAME = transmission;
|
PRODUCT_NAME = transmission;
|
||||||
};
|
};
|
||||||
|
|
18
configure
vendored
18
configure
vendored
|
@ -180,6 +180,23 @@ EOF
|
||||||
rm -f testconf*
|
rm -f testconf*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
libgen_test()
|
||||||
|
{
|
||||||
|
verbose libgen_test
|
||||||
|
cat > testconf.c << EOF
|
||||||
|
#include <libgen.h>
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
if runcmd $CC -o testconf testconf.c
|
||||||
|
then
|
||||||
|
CFLAGS="$CFLAGS -DHAVE_LIBGEN"
|
||||||
|
fi
|
||||||
|
rm -f testconf*
|
||||||
|
}
|
||||||
|
|
||||||
gettext_test()
|
gettext_test()
|
||||||
{
|
{
|
||||||
verbose gettext_test
|
verbose gettext_test
|
||||||
|
@ -450,6 +467,7 @@ lrintf_test
|
||||||
#
|
#
|
||||||
strlcpy_test
|
strlcpy_test
|
||||||
strlcat_test
|
strlcat_test
|
||||||
|
libgen_test
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate config.mk
|
# Generate config.mk
|
||||||
|
|
67
libtransmission/basename.c
Normal file
67
libtransmission/basename.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* $OpenBSD: basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HAVE_LIBGEN
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
basename(const char *path)
|
||||||
|
{
|
||||||
|
static char bname[MAXPATHLEN];
|
||||||
|
size_t len;
|
||||||
|
const char *endp, *startp;
|
||||||
|
|
||||||
|
/* Empty or NULL string gets treated as "." */
|
||||||
|
if (path == NULL || *path == '\0') {
|
||||||
|
bname[0] = '.';
|
||||||
|
bname[1] = '\0';
|
||||||
|
return (bname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strip any trailing slashes */
|
||||||
|
endp = path + strlen(path) - 1;
|
||||||
|
while (endp > path && *endp == '/')
|
||||||
|
endp--;
|
||||||
|
|
||||||
|
/* All slashes becomes "/" */
|
||||||
|
if (endp == path && *endp == '/') {
|
||||||
|
bname[0] = '/';
|
||||||
|
bname[1] = '\0';
|
||||||
|
return (bname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find the start of the base */
|
||||||
|
startp = endp;
|
||||||
|
while (startp > path && *(startp - 1) != '/')
|
||||||
|
startp--;
|
||||||
|
|
||||||
|
len = endp - startp + 1;
|
||||||
|
if (len >= sizeof(bname)) {
|
||||||
|
errno = ENAMETOOLONG;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
memcpy(bname, startp, len);
|
||||||
|
bname[len] = '\0';
|
||||||
|
return (bname);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_LIBGEN */
|
71
libtransmission/dirname.c
Normal file
71
libtransmission/dirname.c
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* $OpenBSD: dirname.c,v 1.13 2005/08/08 08:05:33 espie Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HAVE_LIBGEN
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
dirname(const char *path)
|
||||||
|
{
|
||||||
|
static char dname[MAXPATHLEN];
|
||||||
|
size_t len;
|
||||||
|
const char *endp;
|
||||||
|
|
||||||
|
/* Empty or NULL string gets treated as "." */
|
||||||
|
if (path == NULL || *path == '\0') {
|
||||||
|
dname[0] = '.';
|
||||||
|
dname[1] = '\0';
|
||||||
|
return (dname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strip any trailing slashes */
|
||||||
|
endp = path + strlen(path) - 1;
|
||||||
|
while (endp > path && *endp == '/')
|
||||||
|
endp--;
|
||||||
|
|
||||||
|
/* Find the start of the dir */
|
||||||
|
while (endp > path && *endp != '/')
|
||||||
|
endp--;
|
||||||
|
|
||||||
|
/* Either the dir is "/" or there are no slashes */
|
||||||
|
if (endp == path) {
|
||||||
|
dname[0] = *endp == '/' ? '/' : '.';
|
||||||
|
dname[1] = '\0';
|
||||||
|
return (dname);
|
||||||
|
} else {
|
||||||
|
/* Move forward past the separating slashes */
|
||||||
|
do {
|
||||||
|
endp--;
|
||||||
|
} while (endp > path && *endp == '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
len = endp - path + 1;
|
||||||
|
if (len >= sizeof(dname)) {
|
||||||
|
errno = ENAMETOOLONG;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
memcpy(dname, path, len);
|
||||||
|
dname[len] = '\0';
|
||||||
|
return (dname);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_LIBGEN */
|
|
@ -12,7 +12,6 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libgen.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdio.h> /* FILE, snprintf, stderr */
|
#include <stdio.h> /* FILE, snprintf, stderr */
|
||||||
|
|
||||||
|
|
|
@ -36,4 +36,13 @@ size_t
|
||||||
strlcat(char *dst, const char *src, size_t siz);
|
strlcat(char *dst, const char *src, size_t siz);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBGEN
|
||||||
|
# include <libgen.h>
|
||||||
|
#else
|
||||||
|
char *
|
||||||
|
dirname(const char *path);
|
||||||
|
char *
|
||||||
|
basename(const char *path);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* TRCOMPAT_H */
|
#endif /* TRCOMPAT_H */
|
||||||
|
|
|
@ -6,7 +6,8 @@ include ../mk/common.mk
|
||||||
SRCS = bencode.c choking.c clients.c completion.c fastresume.c fdlimit.c \
|
SRCS = bencode.c choking.c clients.c completion.c fastresume.c fdlimit.c \
|
||||||
http.c inout.c ipcparse.c list.c makemeta.c metainfo.c natpmp.c \
|
http.c inout.c ipcparse.c list.c makemeta.c metainfo.c natpmp.c \
|
||||||
net.c peer.c platform.c ratecontrol.c sha1.c shared.c strlcat.c \
|
net.c peer.c platform.c ratecontrol.c sha1.c shared.c strlcat.c \
|
||||||
strlcpy.c torrent.c tracker.c transmission.c upnp.c utils.c xml.c
|
strlcpy.c torrent.c tracker.c transmission.c upnp.c utils.c xml.c \
|
||||||
|
basename.c dirname.c
|
||||||
|
|
||||||
OBJS = $(SRCS:%.c=%.o)
|
OBJS = $(SRCS:%.c=%.o)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue