mirror of
https://github.com/troglobit/libite.git
synced 2026-11-09 16:21:18 +00:00
Add Westermo chomp() function, slightly improved from Finit original.
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com> Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
745256909e
commit
121e8ee888
4 files changed
+68
-11
No files matched your search
@@ -46,7 +46,7 @@ MAKEFLAGS = --no-print-directory --silent
|
|||||||
|
|
||||||
DISTFILES = README LICENSE
|
DISTFILES = README LICENSE
|
||||||
HEADERS = lite.h
|
HEADERS = lite.h
|
||||||
OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o
|
OBJS := chomp.o copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o
|
||||||
OBJS += strlcpy.o strlcat.o strtonum.o
|
OBJS += strlcpy.o strlcat.o strtonum.o
|
||||||
DEPS := $(OBJS:.o=.d)
|
DEPS := $(OBJS:.o=.d)
|
||||||
JUNK = *~ *.bak *.map .*.d *.d DEADJOE semantic.cache *.gdb *.elf core core.*
|
JUNK = *~ *.bak *.map .*.d *.d DEADJOE semantic.cache *.gdb *.elf core core.*
|
||||||
|
|||||||
@@ -8,21 +8,20 @@ missing C library functions.
|
|||||||
Generic Functions
|
Generic Functions
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- `chomp(str)`
|
||||||
|
|
||||||
|
Perl like chomp function, chop off last char if newline.
|
||||||
|
|
||||||
|
- `copyfile(src, dst, len, symlink)`
|
||||||
|
|
||||||
|
Like the shell `cp(1)` and `dd(1),` can also create symlinks.
|
||||||
|
|
||||||
- `dir(dir, ext, filter, list, strip)`
|
- `dir(dir, ext, filter, list, strip)`
|
||||||
|
|
||||||
Wrapper for `scandir()` with optional filter. Returns a list of
|
Wrapper for `scandir()` with optional filter. Returns a list of
|
||||||
names: files and directories that must be freed after use. See
|
names: files and directories that must be freed after use. See
|
||||||
the unit test at the bottom for an example.
|
the unit test at the bottom for an example.
|
||||||
|
|
||||||
- `rsync(src, dst, delete, *filter())`
|
|
||||||
|
|
||||||
Very simple `rsync()` to copy files files and directories
|
|
||||||
recursively.
|
|
||||||
|
|
||||||
- `copyfile(src, dst, len, symlink)`
|
|
||||||
|
|
||||||
Like the shell `cp(1)` and `dd(1),` can also create symlinks.
|
|
||||||
|
|
||||||
- `fexist(file)`
|
- `fexist(file)`
|
||||||
|
|
||||||
Check for the existance of a file, returns True(1) or False(0).
|
Check for the existance of a file, returns True(1) or False(0).
|
||||||
@@ -35,6 +34,11 @@ Generic Functions
|
|||||||
|
|
||||||
Returns the `mode_t` bits of a file or directory.
|
Returns the `mode_t` bits of a file or directory.
|
||||||
|
|
||||||
|
- `rsync(src, dst, delete, *filter())`
|
||||||
|
|
||||||
|
Very simple `rsync()` to copy files files and directories
|
||||||
|
recursively.
|
||||||
|
|
||||||
|
|
||||||
OpenBSD Functions
|
OpenBSD Functions
|
||||||
-----------------
|
-----------------
|
||||||
@@ -50,7 +54,6 @@ TODO
|
|||||||
----
|
----
|
||||||
|
|
||||||
- Improve documentation, possibly use kdoc or gdoc2 to generate docs from API.
|
- Improve documentation, possibly use kdoc or gdoc2 to generate docs from API.
|
||||||
- Add `chomp()` from Finit
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* Perl inspired chomp() implementation.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* chomp - Perl like chomp function, chop off last char if newline.
|
||||||
|
* @str: String to chomp
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* If @str is a valid pointer this function returns @str, otherwise
|
||||||
|
* @errno is set to %EINVAL and this function returns %NULL.
|
||||||
|
*/
|
||||||
|
char *chomp (char *str)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = strrchr (str, '\n');
|
||||||
|
if (p)
|
||||||
|
*p = 0;
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* version-control: t
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* c-file-style: "ellemtel"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -33,6 +33,8 @@
|
|||||||
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
char *chomp (char *str);
|
||||||
|
|
||||||
int fexist (char *file);
|
int fexist (char *file);
|
||||||
int fisdir (char *file);
|
int fisdir (char *file);
|
||||||
mode_t fmode (char *file);
|
mode_t fmode (char *file);
|
||||||
|
|||||||
Reference in new issue
Block a user