mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34097d33b6 | ||
|
|
311288eec9 | ||
|
|
63cf8867c5 | ||
|
|
ac7b4194cf | ||
|
|
e44aaa4fd5 | ||
|
|
97cb2cb87c | ||
|
|
837c3f23be | ||
|
|
4e9b5c13c1 | ||
|
|
d61b847e55 | ||
|
|
90fdcdeb39 | ||
|
|
e36ac8f462 | ||
|
|
eb3bb94cfa | ||
|
|
11b9c88732 | ||
|
|
11d4aafce1 | ||
|
|
5cdc5736f3 | ||
|
|
059bfd7806 | ||
|
|
0cda6339a4 | ||
|
|
8120492fc8 | ||
|
|
2065165ae9 | ||
|
|
95e5fdba9b | ||
|
|
b21d1c8e9b | ||
|
|
5b670951a3 | ||
|
|
612290c9e2 | ||
|
|
80d11dccf7 | ||
|
|
438e7a2722 | ||
|
|
96e023e58e | ||
|
|
67a9b379ba | ||
|
|
1c0988b8e2 | ||
|
|
407b8f6dbf | ||
|
|
bc72e1c3ad | ||
|
|
2d10cf0402 | ||
|
|
7adf2a01f2 | ||
|
|
a4ff8cce01 |
No files matched your search
+62
-1
@@ -4,6 +4,64 @@ Change Log
|
||||
All notable changes to the project are documented in this file.
|
||||
|
||||
|
||||
[v2.5.3][] - 2023-04-08
|
||||
-----------------------
|
||||
|
||||
### Changes
|
||||
- Refactor `copyfile()` unit test and verify number of bytes copied
|
||||
- Add missing `rsync()` unit test to ensure proper function
|
||||
|
||||
### Fixes
|
||||
- `rsync()` does not copy single files correctly
|
||||
- `copyfile()` does not handle empty source files correctly (error)
|
||||
- `copyfile()` does not properly create destination dir
|
||||
|
||||
|
||||
[v2.5.2][] - 2022-04-17
|
||||
-----------------------
|
||||
|
||||
### Changes
|
||||
- Add printf format attribute hint to all vararg functions. This will
|
||||
help users of these functions by telling CC what to look for
|
||||
|
||||
### Fixes
|
||||
- Fix `fisdir()` segfault on GNU/Hurd
|
||||
- Fix `touch)` on Debian/kFreeBSD, use `creat()` instad of `mknod()`
|
||||
|
||||
|
||||
[v2.5.1][] - 2021-12-02
|
||||
-----------------------
|
||||
|
||||
Debian-only fix.
|
||||
|
||||
### Fixes
|
||||
- Use `dh_link(1)` to install `/usr/include/lite -> libite/`. The
|
||||
symlink created by libite installer itself is not kept.
|
||||
|
||||
|
||||
[v2.5.0][] - 2021-11-30
|
||||
-----------------------
|
||||
|
||||
> **Note:** namespace change; the -lite library include files have moved
|
||||
> from `lite/*.h` to `libite/*.h` due to an unfortunate clash
|
||||
> with "LiTE is a Toobox Engine", from the DirectFB project.
|
||||
> For a transitional period, however, a compatibility symlink
|
||||
> is installed; `lite -> libite/`.
|
||||
|
||||
### Changes
|
||||
- Header files have moved from `lite/*.h` to `libite/*.h` to prevent
|
||||
clashing with DirectFB LiTE library.
|
||||
- Include guards in header files have been renamed, much in the same
|
||||
fashion as the move (above), from `LITE_foo_H_` to `LIBITE_FOO_H_`
|
||||
- Add configure option to disable compatibility symlink, for systems
|
||||
that do not want name clashes with DirectFB/LiTE, or do not need to
|
||||
be backwards compatible; use `configure --without-symlink`
|
||||
|
||||
### Fixes
|
||||
- Minor, use defensive coding in `strnlen()` replacement. Only used
|
||||
on systems that do not have a native implementation.
|
||||
|
||||
|
||||
[v2.4.1][] - 2021-10-09
|
||||
-----------------------
|
||||
|
||||
@@ -430,7 +488,10 @@ problems this may cause!
|
||||
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
||||
|
||||
|
||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.4.1...HEAD
|
||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.5.2...HEAD
|
||||
[v2.5.2]: https://github.com/troglobit/libite/compare/v2.5.1...v2.5.2
|
||||
[v2.5.1]: https://github.com/troglobit/libite/compare/v2.5.0...v2.5.1
|
||||
[v2.5.0]: https://github.com/troglobit/libite/compare/v2.4.1...v2.5.0
|
||||
[v2.4.1]: https://github.com/troglobit/libite/compare/v2.4.0...v2.4.1
|
||||
[v2.4.0]: https://github.com/troglobit/libite/compare/v2.3.1...v2.4.0
|
||||
[v2.3.1]: https://github.com/troglobit/libite/compare/v2.3.0...v2.3.1
|
||||
|
||||
@@ -45,31 +45,54 @@ Using -lite
|
||||
|
||||
Libite is by default installed as a library and a set of include files.
|
||||
To prevent clashing with include files of the same name `-lite` employs
|
||||
an include file namespace `lite/`, which is strongly recommended to use
|
||||
in your applications:
|
||||
an include file namespace `libite/`, which is strongly recommended to
|
||||
use in your applications:
|
||||
|
||||
#include <lite/lite.h>
|
||||
#include <lite/conio.h>
|
||||
#include <lite/queue.h>
|
||||
#include <lite/tree.h>
|
||||
```C
|
||||
#include <libite/lite.h>
|
||||
#include <libite/conio.h>
|
||||
#include <libite/queue.h>
|
||||
#include <libite/tree.h>
|
||||
```
|
||||
|
||||
The output from the `pkg-config` tool holds no surprises in this regard:
|
||||
> **Note:** prior to v2.5.0, the `lite/` namespace was used for headers,
|
||||
> which is still available in the default install. This clashed with
|
||||
> the headers of the LiTE library from the DirectFB project.
|
||||
|
||||
$ pkg-config --libs --static --cflags libite
|
||||
-I/usr/local/include -L/usr/local/lib -lite
|
||||
The output from the `pkg-config` tool holds no surprises:
|
||||
|
||||
```bash
|
||||
$ pkg-config --libs --static --cflags libite
|
||||
-I/usr/local/include -D_LIBITE_LITE -L/usr/local/lib -lite
|
||||
```
|
||||
|
||||
> **Note:** `_LIBITE_LITE` is defined since v2.5.0, useful for software
|
||||
> that want to be able to build against headers from an older libite:
|
||||
>
|
||||
> ```C
|
||||
> #ifdef _LIBITE_LITE
|
||||
> # include <libite/lite.h>
|
||||
> #else
|
||||
> # include <lite/lite.h>
|
||||
> #endif
|
||||
> ```
|
||||
|
||||
The prefix path `/usr/local/` shown here is only the default. Use the
|
||||
`configure` script to select a different prefix when installing libite.
|
||||
|
||||
For GNU autotools based projects, use the following in `configure.ac`:
|
||||
|
||||
# Check for required libraries
|
||||
PKG_CHECK_MODULES([lite], [libite >= 1.5.0])
|
||||
```m4
|
||||
# Check for required libraries
|
||||
PKG_CHECK_MODULES([lite], [libite >= 1.5.0])
|
||||
```
|
||||
|
||||
and in your `Makefile.am`:
|
||||
|
||||
proggy_CFLAGS = $(lite_CFLAGS)
|
||||
proggy_LDADD = $(lite_LIBS)
|
||||
```Makefile
|
||||
proggy_CFLAGS = $(lite_CFLAGS)
|
||||
proggy_LDADD = $(lite_LIBS)
|
||||
```
|
||||
|
||||
> API Documentaion: https://codedocs.xyz/troglobit/libite/
|
||||
|
||||
@@ -80,10 +103,18 @@ Build & Install
|
||||
This library was initially built for and developed on GNU/Linux systems
|
||||
as a light weight utility library, these days NetBSD should also work.
|
||||
|
||||
./configure
|
||||
make -j5
|
||||
sudo make install-strip
|
||||
sudo ldconfig
|
||||
```bash
|
||||
$ ./configure
|
||||
$ make -j5
|
||||
$ sudo make install-strip
|
||||
$ sudo ldconfig
|
||||
```
|
||||
|
||||
Use <kbd>./configure --without-symlink</kbd> to prevent the install step
|
||||
from creating the `lite -> libite/` compatibility symlink for the header
|
||||
files, required for systems with DirectFB LiTE. The default, however,
|
||||
is to install the symlink to ensure compatibility with existing software
|
||||
that depends on the `-lite` library headers in their previous namespace.
|
||||
|
||||
**Note:** When checking out code from GIT, use <kbd>./autogen.sh</kbd>
|
||||
to generate a `configure` script. It is a generated file and otherwise
|
||||
|
||||
+9
-3
@@ -1,4 +1,4 @@
|
||||
AC_INIT(libite, 2.4.1, https://github.com/troglobit/libite/issues)
|
||||
AC_INIT(libite, 2.5.3, https://github.com/troglobit/libite/issues)
|
||||
AC_CONFIG_AUX_DIR(aux)
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
|
||||
AM_SILENT_RULES([yes])
|
||||
@@ -27,7 +27,13 @@ DX_CHM_FEATURE(OFF)
|
||||
DX_HTML_FEATURE(ON)
|
||||
DX_MAN_FEATURE(OFF)
|
||||
DX_INIT_DOXYGEN(${PACKAGE_NAME}, [${top_builddir}/doc/Doxyfile], [${top_builddir}/doc])
|
||||
AM_CONDITIONAL(ENABLE_DOXYGEN,[test "x${DX_FLAG_doc}" = x1])
|
||||
AM_CONDITIONAL(ENABLE_HTML,[test "x${DX_FLAG_html}" = x1])
|
||||
|
||||
AC_ARG_WITH([symlink],
|
||||
AS_HELP_STRING([--without-symlink], [Disable compat /usr/include/lite -> libite symlink]),,
|
||||
[with_symlink=yes])
|
||||
|
||||
AM_CONDITIONAL([ENABLE_DOXYGEN], [test "x${DX_FLAG_doc}" = x1])
|
||||
AM_CONDITIONAL([ENABLE_HTML], [test "x${DX_FLAG_html}" = x1])
|
||||
AM_CONDITIONAL([COMPAT_SYMLINK], [test "x$with_symlink" != "xno"])
|
||||
|
||||
AC_OUTPUT
|
||||
Vendored
+25
@@ -1,3 +1,28 @@
|
||||
libite (2.5.3) stable; urgency=medium
|
||||
|
||||
* rsync() does not copy single files correctly
|
||||
* copyfile() does not handle empty source files correctly (error)
|
||||
* copyfile() does not properly create destination dir
|
||||
* Add printf format attribute hint to all vararg functions
|
||||
* Fix fisdir() segfault on GNU/Hurd
|
||||
* Fix touch() on Debian/kFreeBSD, use creat() instad of mknod()
|
||||
|
||||
-- Joachim Wiberg <troglobit@gmail.com> Sat, 08 Apr 2023 07:04:00 +0200
|
||||
|
||||
libite (2.5.1) stable; urgency=medium
|
||||
|
||||
* Use dh_link(1) to install `/usr/include/lite -> libite/`.
|
||||
|
||||
-- Joachim Wiberg <troglobit@gmail.com> Thu, 02 Dec 2021 00:08:41 +0100
|
||||
|
||||
libite (2.5.0) stable; urgency=medium
|
||||
|
||||
* Header files have moved from `lite/*.h` to `libite/*.h` to prevent
|
||||
clashing with DirectFB LiTE library. For a transitional period,
|
||||
however, a compatibility symlink is installed; `lite -> libite/`.
|
||||
|
||||
-- Joachim Wiberg <troglobit@gmail.com> Tue, 30 Nov 2021 06:57:17 +0100
|
||||
|
||||
libite (2.4.1) stable; urgency=medium
|
||||
|
||||
* Add doxygen documentation, https://codedocs.xyz/troglobit/libite/
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
usr/include/lite/*.h
|
||||
usr/include/libite/*.h
|
||||
usr/lib/*/lib*.a
|
||||
usr/lib/*/lib*.so
|
||||
usr/lib/*/pkgconfig/lib*.pc
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/usr/include/libite /usr/include/lite
|
||||
Vendored
+3
@@ -6,6 +6,9 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||
%:
|
||||
dh $@ --with autoreconf
|
||||
|
||||
override_dh_auto_configure:
|
||||
dh_auto_configure -- --without-symlink
|
||||
|
||||
override_dh_installchangelogs:
|
||||
dh_installchangelogs ChangeLog.md
|
||||
|
||||
|
||||
+18
-3
@@ -2,7 +2,7 @@ lib_LTLIBRARIES = libite.la
|
||||
|
||||
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
||||
libite_la_CFLAGS = -W -Wall -Wextra
|
||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 8:1:3
|
||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 8:2:3
|
||||
libite_la_SOURCES = chomp.c copyfile.c \
|
||||
conio.c conio.h dir.c \
|
||||
erasef.c fopenf.c fremove.c \
|
||||
@@ -21,10 +21,25 @@ libite_la_SOURCES = chomp.c copyfile.c \
|
||||
queue.h tree.h
|
||||
|
||||
|
||||
## Distribute these header files in the <lite/...> name space
|
||||
pkgincludedir = $(includedir)/lite
|
||||
## Distribute these header files in the <libite/...> namespace
|
||||
pkgincludedir = $(includedir)/libite
|
||||
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h \
|
||||
strndupa.h strnlen.h
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libite.pc
|
||||
|
||||
## For compatibility with previous <lite/...> namespace
|
||||
if COMPAT_SYMLINK
|
||||
install-data-hook:
|
||||
link=$(DESTDIR)$(includedir)/lite; \
|
||||
if [ ! -f $$link ]; then \
|
||||
$(LN_S) libite $$link; \
|
||||
fi
|
||||
|
||||
uninstall-hook:
|
||||
link=$(shell readlink $(DESTDIR)$(includedir)/lite); \
|
||||
if [ "$$link" = "libite" ]; then \
|
||||
$(RM) $(DESTDIR)$(includedir)/lite; \
|
||||
fi
|
||||
endif
|
||||
+3
-3
@@ -29,8 +29,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef CONIO_H_
|
||||
#define CONIO_H_
|
||||
#ifndef LIBITE_CONIO_H_
|
||||
#define LIBITE_CONIO_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -130,7 +130,7 @@ static inline void printheader(FILE *fp, const char *line, int nl)
|
||||
printhdr(fp, line, nl, REVERSE);
|
||||
}
|
||||
|
||||
#endif /* CONIO_H_ */
|
||||
#endif /* LIBITE_CONIO_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+20
-5
@@ -38,6 +38,7 @@ static int adjust_target(const char *src, char **dst)
|
||||
{
|
||||
int isdir = 0;
|
||||
|
||||
retry:
|
||||
if (fisdir(*dst)) {
|
||||
int slash = 0;
|
||||
char *tmp, *ptr = strrchr(src, '/');
|
||||
@@ -58,16 +59,25 @@ static int adjust_target(const char *src, char **dst)
|
||||
|
||||
sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr);
|
||||
*dst = tmp;
|
||||
} else {
|
||||
struct stat st;
|
||||
|
||||
if (stat(*dst, &st) && fisslashdir(*dst)) {
|
||||
makedir(*dst, 0755);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
||||
return isdir;
|
||||
}
|
||||
|
||||
/* Actual copy loop, used by both copyfile() and fcopyfile()
|
||||
* breaks loop on error and EOF */
|
||||
/*
|
||||
* Actual copy loop, used by both copyfile() and fcopyfile() breaks loop
|
||||
* on error and EOF
|
||||
*/
|
||||
static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
|
||||
{
|
||||
ssize_t ret = 0, size = 0;
|
||||
ssize_t ret = 0, size = -1;
|
||||
|
||||
do {
|
||||
size_t count = num > len ? len : num;
|
||||
@@ -76,11 +86,16 @@ static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
|
||||
if (ret <= 0) {
|
||||
if (ret == -1 && EINTR == errno)
|
||||
continue;
|
||||
if (ret == 0 && size == -1)
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret > 0)
|
||||
if (ret > 0) {
|
||||
if (size == -1)
|
||||
size = 0;
|
||||
size += write(out, buffer, ret);
|
||||
}
|
||||
num -= count;
|
||||
} while (num > 0);
|
||||
|
||||
@@ -194,7 +209,7 @@ ssize_t copyfile(const char *src, const char *dst, int len, int opt)
|
||||
}
|
||||
|
||||
size = do_copy(in, out, num, buffer, BUFSIZ);
|
||||
if (!size && errno)
|
||||
if (size < 0)
|
||||
saved_errno = errno;
|
||||
else if (keep_mtim)
|
||||
set_mtime(in, out);
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ int fisdir(const char *path)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (!stat(path, &sb) && S_ISDIR(sb.st_mode))
|
||||
if (path && !stat(path, &sb) && S_ISDIR(sb.st_mode))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
||||
+1
-2
@@ -8,5 +8,4 @@ Description: Frog DNA, basically
|
||||
Version: @VERSION@
|
||||
Requires:
|
||||
Libs: -L${libdir} -lite
|
||||
Cflags: -I${includedir}
|
||||
|
||||
Cflags: -I${includedir} -D_LIBITE_LITE
|
||||
+19
-14
@@ -38,8 +38,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_H_
|
||||
#define LITE_H_
|
||||
#ifndef LIBITE_LITE_H_
|
||||
#define LIBITE_LITE_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> /* Definition of AT_* constants for utimensat() */
|
||||
@@ -72,21 +72,21 @@ typedef struct sdbuf sdbuf_t; /**< Opqaue context struct for telnet APIs */
|
||||
|
||||
char *chomp (char *str);
|
||||
|
||||
int erasef (const char *fmt, ...);
|
||||
int erasef (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
||||
|
||||
int fexist (const char *file);
|
||||
int fisdir (const char *path);
|
||||
|
||||
FILE *fopenf (const char *mode, const char *fmt, ...);
|
||||
int fremove (const char *fmt, ...);
|
||||
FILE *fopenf (const char *mode, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
int fremove (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
FILE *tempfile (void);
|
||||
ssize_t copyfile (const char *src, const char *dst, int len, int opt);
|
||||
int movefile (const char *src, const char *dst);
|
||||
int fcopyfile (FILE *src, FILE *dst);
|
||||
ssize_t fsendfile (FILE *src, FILE *dst, size_t len);
|
||||
int truncatef (off_t length, const char *fmt, ...);
|
||||
int truncatef (off_t length, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
int ifconfig (const char *ifname, const char *addr, const char *mask, int up);
|
||||
|
||||
@@ -97,7 +97,7 @@ char *lfgetkey (lfile_t *lf, const char *key);
|
||||
int lfgetint (lfile_t *lf, const char *key);
|
||||
int fgetint (const char *file, const char *sep, const char *key);
|
||||
|
||||
int fmkpath (mode_t mode, const char *fmt, ...);
|
||||
int fmkpath (mode_t mode, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
int mkpath (const char *dir, mode_t mode);
|
||||
int makepath (const char *dir);
|
||||
|
||||
@@ -114,16 +114,16 @@ void *reallocarray(void *optr, size_t nmemb, size_t size);
|
||||
void progress (int percent, int max_width);
|
||||
void progress_simple(int percent);
|
||||
|
||||
int systemf (const char *fmt, ...);
|
||||
int systemf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
sdbuf_t*telnet_open (int addr, short port);
|
||||
int telnet_close (sdbuf_t *ctx);
|
||||
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output);
|
||||
int telnet_session (int addr, short port, char *script[], FILE *output);
|
||||
|
||||
int touchf (const char *fmt, ...);
|
||||
int touchf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
int yorn (const char *fmt, ...);
|
||||
int yorn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
char *which (const char *cmd);
|
||||
int whichp (const char *cmd);
|
||||
@@ -139,10 +139,15 @@ int whichp (const char *cmd);
|
||||
*/
|
||||
static inline int touch(const char *path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (utimensat(AT_FDCWD, path, NULL, 0)) {
|
||||
if (errno == ENOENT)
|
||||
return mknod((path), S_IFREG|0644, 0);
|
||||
return -1;
|
||||
if (errno != ENOENT)
|
||||
return -1;
|
||||
fd = creat(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -245,7 +250,7 @@ static inline int fisslashdir(const char *dir)
|
||||
#define pidfile_read_pid(file) pidfile_read(file)
|
||||
#define signal_pidfile(file, signo) pidfile_signal(file, signo)
|
||||
|
||||
#endif /* LITE_H_ */
|
||||
#endif /* LIBITE_LITE_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+5
-3
@@ -77,7 +77,9 @@ int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
||||
char **files; /* Array of file names. */
|
||||
struct stat st;
|
||||
|
||||
if (!fisdir(dst))
|
||||
errno = 0;
|
||||
|
||||
if (stat(dst, &st) && fisslashdir(dst))
|
||||
makedir(dst, 0755);
|
||||
|
||||
if (!fisdir(src)) {
|
||||
@@ -85,9 +87,9 @@ int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
||||
return 1;
|
||||
|
||||
if (copy(src, dst, keep_mtim))
|
||||
result++;
|
||||
return 1;
|
||||
|
||||
return errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Copy dir as well? */
|
||||
|
||||
+3
-3
@@ -36,8 +36,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRDUPA_H
|
||||
#define LITE_STRDUPA_H
|
||||
#ifndef LIBITE_STRDUPA_H
|
||||
#define LIBITE_STRDUPA_H
|
||||
|
||||
#if !defined(HAVE_STRDUPA)
|
||||
#if defined(strdupa)
|
||||
@@ -67,7 +67,7 @@ extern "C"
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* !HAVE_STRDUPA */
|
||||
|
||||
#endif /* LITE_STRDUPA_H */
|
||||
#endif /* LIBITE_STRDUPA_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+3
-3
@@ -33,8 +33,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRING_H_
|
||||
#define LITE_STRING_H_
|
||||
#ifndef LIBITE_STRING_H_
|
||||
#define LIBITE_STRING_H_
|
||||
|
||||
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
|
||||
#include <string.h>
|
||||
@@ -143,7 +143,7 @@ static inline int string_case_compare(const char *a, const char *b)
|
||||
return strlen(a) == strlen(b) && !strcasecmp(a, b);
|
||||
}
|
||||
|
||||
#endif /* LITE_STRING_H_ */
|
||||
#endif /* LIBITE_STRING_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+3
-3
@@ -36,8 +36,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRNDUPA_H_
|
||||
#define LITE_STRNDUPA_H_
|
||||
#ifndef LIBITE_STRNDUPA_H_
|
||||
#define LIBITE_STRNDUPA_H_
|
||||
|
||||
#if !defined(HAVE_STRNDUPA)
|
||||
#if defined(strndupa)
|
||||
@@ -69,7 +69,7 @@ extern "C"
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* !HAVE_STRNDUPA */
|
||||
|
||||
#endif /* GNU_STRING_STRNDUPA_H */
|
||||
#endif /* LIBITE_STRNDUPA_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+4
-4
@@ -27,8 +27,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRNLEN_H_
|
||||
#define LITE_STRNLEN_H_
|
||||
#ifndef LIBITE_STRNLEN_H_
|
||||
#define LIBITE_STRNLEN_H_
|
||||
|
||||
#if !defined(HAVE_STRNLEN)
|
||||
#if defined(strnlen)
|
||||
@@ -51,14 +51,14 @@ static inline size_t xstrnlen(const char *str, size_t lim)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
while (str[i] && i < lim)
|
||||
while (i < lim && str[i])
|
||||
i++;
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LITE_STRNLEN_H_ */
|
||||
#endif /* LIBITE_STRNLEN_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
#ifndef LITE_TESTS_CHECK_H_
|
||||
#define LITE_TESTS_CHECK_H_
|
||||
#ifndef LIBLITE_TESTS_CHECK_H_
|
||||
#define LIBLITE_TESTS_CHECK_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
@@ -78,4 +78,4 @@ static inline char *timespec2str(struct timespec *ts, char *buf, size_t len)
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* LITE_TESTS_CHECK_H_ */
|
||||
#endif /* LIBLITE_TESTS_CHECK_H_ */
|
||||
+124
-48
@@ -2,54 +2,130 @@
|
||||
#include <errno.h>
|
||||
#include "check.h"
|
||||
|
||||
#define ERR(fmt, args...) { printf(fmt ": %s\n", ##args, strerror(errno)); rc = 1; }
|
||||
#define ERRX(fmt, args...) { printf(fmt "\n", ##args); rc = 1; }
|
||||
|
||||
static char *files[] = {
|
||||
"/etc/passwd", "/tmp/mypwd", "/tmp/mypwd",
|
||||
"/etc/passwd", "/tmp/", "/tmp/passwd",
|
||||
"/etc/passwd", "/tmp", "/tmp/passwd",
|
||||
NULL
|
||||
};
|
||||
|
||||
static int one_sz(const char *src, const char *dst, int sz)
|
||||
{
|
||||
struct stat st;
|
||||
ssize_t len;
|
||||
int rc = 0;
|
||||
|
||||
len = copyfile(src, dst, sz, 0);
|
||||
if (!len) {
|
||||
ERR("failed copying any bytes from %s", src);
|
||||
} else {
|
||||
if (stat(dst, &st))
|
||||
ERR("copied but cannot find destination %s", dst);
|
||||
|
||||
if (st.st_size != sz)
|
||||
ERR("file only %ld bytes, expected %d", st.st_size, sz);
|
||||
|
||||
if (len != st.st_size)
|
||||
ERRX("copied expected data %d, but copyfile() says %ld", sz, len);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int _sz()
|
||||
{
|
||||
const int sz = 32768;
|
||||
|
||||
return test(one_sz("/dev/zero", "/tmp/zeroes", sz), "copyfile(/dev/zero, %d)", sz);
|
||||
}
|
||||
|
||||
static int fcopyfile_one(const char *src, const char *dst, const char *expected)
|
||||
{
|
||||
FILE *from, *to;
|
||||
int rc;
|
||||
|
||||
from = fopen(src, "r");
|
||||
to = fopen(dst, "w");
|
||||
|
||||
rc = fcopyfile(from, to);
|
||||
|
||||
if (from)
|
||||
fclose(from);
|
||||
if (to)
|
||||
fclose(to);
|
||||
|
||||
if (rc) {
|
||||
if (!src || !dst)
|
||||
rc = 0; /* expected */
|
||||
else if (fisdir(dst))
|
||||
rc = 0; /* expected */
|
||||
} else {
|
||||
if (fexist(expected)) {
|
||||
if (systemf("diff -q %s %s", src, expected))
|
||||
rc = 1;
|
||||
} else
|
||||
ERR("cannot find %s", expected);
|
||||
}
|
||||
|
||||
erase(expected);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int _fcopyfile()
|
||||
{
|
||||
int i, rc = 0;
|
||||
|
||||
for (i = 0; files[i]; i += 3) {
|
||||
char *src = files[i];
|
||||
char *dst = files[i + 1];
|
||||
char *res = files[i + 2];
|
||||
|
||||
rc += test(fcopyfile_one(src, dst, res), "fcopyfile(%s, %s)", src, dst);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* only checks success, correct file size verified by _sz() */
|
||||
static int copyfile_one(const char *src, const char *dst, const char *expected)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = copyfile(src, dst, 0, 0);
|
||||
if (!rc)
|
||||
rc = 1;
|
||||
else if (!fexist(expected))
|
||||
rc = 1;
|
||||
else
|
||||
rc = 0;
|
||||
|
||||
erase(expected);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int _copyfile()
|
||||
{
|
||||
int i, rc = 0;
|
||||
|
||||
for (i = 0; files[i]; i += 3) {
|
||||
char *src = files[i];
|
||||
char *dst = files[i + 1];
|
||||
char *res = files[i + 2];
|
||||
|
||||
rc += test(copyfile_one(src, dst, res), "copyfile(%s, %s)", src, dst);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i = 0;
|
||||
char *files[] = {
|
||||
"/etc/passwd", "/tmp/mypwd", "/tmp/mypwd",
|
||||
"/etc/passwd", "/tmp/", "/tmp/passwd",
|
||||
"/etc/passwd", "/tmp", "/tmp/passwd",
|
||||
NULL
|
||||
};
|
||||
FILE *src, *dst;
|
||||
|
||||
printf("=>Start testing fcopyfile()\n");
|
||||
while (files[i]) {
|
||||
printf("fcopyfile(%s, %s)\t", files[i], files[i + 1]);
|
||||
src = fopen(files[i], "r");
|
||||
dst = fopen(files[i + 1], "w");
|
||||
if (fcopyfile(src, dst)) {
|
||||
if (!fisdir(files[i + 1]))
|
||||
err(1, "Failed fcopyfile(%s, %s)", files[i], files[i + 1]);
|
||||
}
|
||||
|
||||
if (src)
|
||||
fclose(src);
|
||||
if (dst)
|
||||
fclose(dst);
|
||||
|
||||
if (fexist(files[i + 2]))
|
||||
printf("OK => %s", files[i + 2]);
|
||||
printf("\n");
|
||||
|
||||
erase(files[i + 2]);
|
||||
i += 3;
|
||||
}
|
||||
|
||||
printf("\n=>Start testing copyfile()\n");
|
||||
i = 0;
|
||||
while (files[i]) {
|
||||
printf("copyfile(%s, %s)\t", files[i], files[i + 1]);
|
||||
if (!copyfile(files[i], files[i + 1], 0, 0))
|
||||
err(1, "Failed copyfile(%s, %s)", files[i], files[i + 1]);
|
||||
|
||||
if (fexist(files[i + 2]))
|
||||
printf("OK => %s", files[i + 2]);
|
||||
printf("\n");
|
||||
|
||||
erase(files[i + 2]);
|
||||
i += 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return _fcopyfile() ||
|
||||
_copyfile() ||
|
||||
_sz();
|
||||
}
|
||||
+1
-1
@@ -41,7 +41,7 @@ static int mtime()
|
||||
char buf[80];
|
||||
|
||||
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
|
||||
usleep(10000);
|
||||
sleep(2);
|
||||
|
||||
PRINT("Calling pidfile() again to update mtime ...\n");
|
||||
if (pidfile(pidfile_arg))
|
||||
|
||||
+65
-35
@@ -48,52 +48,82 @@ void setup_test(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void check_tree(char *heading, char *dir)
|
||||
int check_dir_to_dir(void)
|
||||
{
|
||||
if (verbose) {
|
||||
if (heading)
|
||||
puts(heading);
|
||||
int rc = 0;
|
||||
|
||||
rc += rsync(SRC, DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||
rc += systemf("diff -rq %s %s", SRC, DST);
|
||||
systemf("rm -rf %s/*", DST);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int check_file_to_file(void)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
touch(SRC "foo.txt");
|
||||
PRINT("SRC ==========================\n");
|
||||
if (verbose) system("ls -l " SRC);
|
||||
rc += rsync(SRC "foo.txt", DST "foo.txt", LITE_FOPT_KEEP_MTIME, NULL);
|
||||
if (!fexist(DST "foo.txt") || fisdir(DST "foo.txt")) {
|
||||
PRINT("No dst file or it's a directory\n");
|
||||
rc++;
|
||||
}
|
||||
|
||||
// XXX: Fixme, add code to list tree, nftw() possibly
|
||||
PRINT("DST ==========================\n");
|
||||
if (verbose) system("ls -l " DST);
|
||||
systemf("rm -rf %s %s/*", SRC "foo.txt" , DST);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int check_file_to_dir(void)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
touch(SRC "foo.txt");
|
||||
PRINT("SRC ==========================\n");
|
||||
if (verbose) system("ls -l " SRC);
|
||||
rc += rsync(SRC "foo.txt", DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||
if (!fexist(DST "foo.txt") || fisdir(DST "foo.txt"))
|
||||
rc++;
|
||||
PRINT("DST ==========================\n");
|
||||
if (verbose) system("ls -l " DST);
|
||||
systemf("rm -rf %s %s/*", SRC "foo.txt" , DST);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int check_file_to_nodir(void)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
touch(SRC "foo.txt");
|
||||
PRINT("SRC ==========================\n");
|
||||
if (verbose) system("ls -l " SRC);
|
||||
system("rm -rf " DST);
|
||||
rc += rsync(SRC "foo.txt", DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||
if (!fexist(DST "foo.txt") || fisdir(DST "foo.txt"))
|
||||
rc++;
|
||||
PRINT("DST ==========================\n");
|
||||
if (verbose) system("ls -l " DST);
|
||||
systemf("rm -rf %s %s/*", SRC "foo.txt" , DST);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int run_test(void)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
#if 0
|
||||
setup_test();
|
||||
check_tree("Before:", BASE);
|
||||
|
||||
result += rsync(SRC, DST, 0, NULL);
|
||||
check_tree("After:", BASE);
|
||||
cleanup_test();
|
||||
#endif
|
||||
|
||||
setup_test();
|
||||
sleep(1);
|
||||
result += rsync(BASE "src", DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||
check_tree("Only partial rsync of src <-- No slash!", BASE);
|
||||
#if 0
|
||||
cleanup_test();
|
||||
setup_test();
|
||||
result += rsync(BASE "src/sub1", BASE "dst", 0, NULL);
|
||||
check_tree("Only partial rsync of src/sub1 <-- No slashes!!", BASE);
|
||||
|
||||
cleanup_test();
|
||||
setup_test();
|
||||
result += rsync(BASE "src/sub1/", DST, 0, NULL);
|
||||
check_tree("Only partial rsync of src/sub1/", BASE);
|
||||
|
||||
cleanup_test();
|
||||
setup_test();
|
||||
result += rsync(BASE "src/sub1", DST, 0, NULL);
|
||||
check_tree("Only partial rsync of src/sub1 <-- No slash!", BASE);
|
||||
|
||||
result += rsync("/etc", "/var/tmp", 0, NULL);
|
||||
check_tree("Real life test:", "/var/tmp");
|
||||
#endif
|
||||
result += test(check_dir_to_dir(), "Verifying src/ -> dst/");
|
||||
result += test(check_file_to_file(), "Verifying src/foo.txt -> dst/foo.txt");
|
||||
result += test(check_file_to_dir(), "Verifying src/foo.txt -> dst/");
|
||||
result += test(check_file_to_nodir(),"Verifying src/foo.txt -> dst/ (non-existing target dir)");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ static int mtime(char *file)
|
||||
stat(file, &before);
|
||||
|
||||
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
|
||||
usleep(10000);
|
||||
sleep(2);
|
||||
|
||||
PRINT("Calling touch() again to update mtime ...\n");
|
||||
if (touch(file)) {
|
||||
|
||||
Reference in new issue
Block a user