Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
9bf8284
Small translate_test example program changes
afxgroup Jun 6, 2024
b713c8a
flockfile/ftrylockfile/funlockfile now are protected by an IOB flag t…
afxgroup Jun 10, 2024
f49faf4
Set pipe() fds to FDF_IS_INTERACTIVE despite the fact, that IsInterac…
elfpipe Jun 12, 2024
04c81af
Merge branch 'beta10' into master
afxgroup Jun 12, 2024
93a82d2
Merge pull request #185 from alfkil/master
afxgroup Jun 12, 2024
b0d964b
Added pipe/block test file. Don't fail if rename is using same name f…
afxgroup Jun 13, 2024
1d57cbc
Remove last / in mkdir if present to avoid errors when creating dir. …
afxgroup Jun 13, 2024
7be89c2
Trying to add waitpid for spawned processes
afxgroup Jun 13, 2024
d30c1ef
Fixed waitpid/wait functions
afxgroup Jun 13, 2024
7e9325e
Merge pull request #186 from AmigaLabs/spawnv
afxgroup Jun 13, 2024
95db1b5
More waitpid/spawnv changes
afxgroup Jun 14, 2024
d4c4689
More waitpid changes
afxgroup Jun 14, 2024
b2d0ae5
Reverse the order of SBM_(NON_)BLOCKING.
elfpipe Jun 15, 2024
a145b76
Merge pull request #188 from alfkil/beta10
afxgroup Jun 16, 2024
1a46978
Added ERROR_WOULD_BLOCK == EWOULDBLOCK to __translate_io_error_to_err…
elfpipe Jun 16, 2024
5795e40
Merge pull request #189 from alfkil/beta10
afxgroup Jun 16, 2024
b0d82d8
Some minor spawnv/waitpid changes. added terminal program that should…
afxgroup Jun 16, 2024
8fdeb39
Fixed a bug in fgets was not including \n
afxgroup Jun 17, 2024
165647f
Fixed broken termios hook
afxgroup Jun 17, 2024
3e53ca0
Added two test programs
afxgroup Jun 19, 2024
9c5e9ff
Trying to find waitpid BUG that prevent a process to be waited correctly
afxgroup Jun 19, 2024
4c71ddf
Moved spawnedProcesses in clib4 node
afxgroup Jun 20, 2024
6a630bf
Added spawnvpe and some debug on waitpid
afxgroup Jun 20, 2024
a88a0a7
Some PIPE/Linux fixes
afxgroup Jun 20, 2024
ac4b060
Some minor close files fixes
afxgroup Jun 22, 2024
9b317fb
Added handling of O_NONBLOCK fds for select/poll.
elfpipe Jun 24, 2024
7a18302
Merge pull request #190 from alfkil/beta10
afxgroup Jun 24, 2024
3f04e3b
Poll mode reported avaibale data,even that isn't the case
migthymax Jun 25, 2024
440f5a7
Poll mode reported avaibale data,even that isn't the case
migthymax Jun 25, 2024
a6271a8
Merge pull request #192 from migthymax/beta10
afxgroup Jun 25, 2024
64fa1fe
Added waitpoll() function
afxgroup Jun 25, 2024
60d5464
Work-in-progress suggestion for an added cli path search for the unix…
elfpipe Jun 27, 2024
fc88501
Flower-dusting path test.
elfpipe Jun 27, 2024
1eb45ac
Cosmetic.
elfpipe Jun 27, 2024
35585cd
Further cosmetics.
elfpipe Jun 27, 2024
64bec46
Merge pull request #193 from alfkil/beta10
afxgroup Jun 29, 2024
30727ef
waitpid code cleaning
afxgroup Jun 29, 2024
2085608
Merge branch 'beta10' of github.com:afxgroup/clib2 into beta10
afxgroup Jun 29, 2024
3cd60f6
Some small fixes to make flto working (clib4 is not compiled with flt…
afxgroup Jul 2, 2024
cb25559
Some memory allocation fixes
afxgroup Jul 2, 2024
b913041
Some other memory allocation changes
afxgroup Jul 2, 2024
a929daf
Change spawnvpe to use CreateNewProc instead of SystemTags
afxgroup Jul 3, 2024
96aca4e
Added fully_initialized to clib4 that signal that all constructors ar…
afxgroup Jul 3, 2024
bfbbeb4
Moved signal member
afxgroup Jul 4, 2024
dcd248d
Added two new test program. pthread_malloc at moment is stuck in floc…
afxgroup Jul 4, 2024
fbf0b17
Cosmetic changes
afxgroup Jul 4, 2024
603c6dd
Replaced Semaphore file lock with recursive mutexes. Fixed a problem …
afxgroup Jul 4, 2024
25a7bf3
Speedup some internal functions now doesn't get __clib4 pointer every…
afxgroup Jul 4, 2024
bc9ebc8
spawnvpe use finalpath as NP_Name. Most probably we have to find a wa…
afxgroup Jul 4, 2024
aafb8c8
More small optimizations to avoid to get __clib4 in many functions
afxgroup Jul 5, 2024
6293411
more reentrant internal functions fixed
afxgroup Jul 8, 2024
32298b1
Reverted back SyetemTags in spawnvpe
afxgroup Jul 8, 2024
417aa04
Added some (private) reentrant functions to speedup internal clib4 calls
afxgroup Jul 12, 2024
31abd36
Fixed some include files
afxgroup Jul 15, 2024
c4858b5
More _clib4 optimizations
afxgroup Jul 15, 2024
5517b9c
Merge branch 'beta10' of github.com:afxgroup/clib2 into beta10
afxgroup Jul 15, 2024
28e868f
More speed improvements and fixes
afxgroup Jul 20, 2024
d8d5cd8
1) Roll back (native) default path search for unix->amiga path transl…
elfpipe Jul 20, 2024
cae4d72
Merge pull request #194 from alfkil/beta10
afxgroup Jul 21, 2024
7cf91a7
Moved aways dos.h from include folder. Now all include should't use O…
afxgroup Jul 21, 2024
3a1e673
Added informations on clib4 repository in README file
afxgroup Jul 21, 2024
3249e6c
Implement spawnvpe_callback.
elfpipe Jul 22, 2024
fff1067
Fixed bad self initialization
afxgroup Jul 23, 2024
dcffd79
Suggestion to implement spawnvpe_callback.
elfpipe Jul 23, 2024
b5000ae
Fix off-by-one bug in spawnvpe.
elfpipe Jul 23, 2024
744bf6e
Merge branch 'beta10' into beta10
elfpipe Jul 23, 2024
97a9913
Tidy up the last commit.
elfpipe Jul 23, 2024
e906fff
Merge branch 'beta10' of https://github.com/alfkil/clib4_path_semanti…
elfpipe Jul 23, 2024
73c4249
Tidy one detail (parenthesis off by one).
elfpipe Jul 23, 2024
8bdf42d
Update popen.c
afxgroup Jul 23, 2024
c1e4578
Merge pull request #196 from alfkil/beta10
afxgroup Jul 23, 2024
d7b9a86
Remove wrong child insertion from latest commit
afxgroup Jul 24, 2024
3954bb5
Fixed some problems when locking streams. Updated qsort function was …
afxgroup Jul 26, 2024
cd42ed8
Fix for SPE compilation
afxgroup Jul 26, 2024
4f32104
Implement the following in spawnvpe : 1) Translate cwd path. 2) Lock …
elfpipe Jul 29, 2024
6bf6c8a
Merge pull request #198 from alfkil/beta10
afxgroup Jul 29, 2024
89ae555
Added test for parent-child interaction and pipe handling + return st…
elfpipe Jul 29, 2024
980f75f
Delete unnecessary files. Rename dir for spawnvpe test.
elfpipe Jul 30, 2024
b8129c2
Merge pull request #199 from alfkil/beta10
afxgroup Jul 30, 2024
ab44a2c
Fixed wrong termcap global variables definitions
afxgroup Jul 31, 2024
df94967
Fixed some wrong printfs and bad function signatures
afxgroup Jul 31, 2024
e595ce1
Merge branch 'beta10' of github.com:afxgroup/clib2 into beta10
afxgroup Jul 31, 2024
2948d88
in abort() function call atexit in case someone has instlled some fun…
afxgroup Aug 1, 2024
161d5da
Removed empty fork file
afxgroup Aug 1, 2024
d709cd0
Fixed fenv.h was not working without _GNU_SOURCE enabled
afxgroup Aug 2, 2024
59bc094
Optimized strchr using PPC code
afxgroup Aug 5, 2024
b3f0efa
Some more optimizations to strchr and memchr
afxgroup Aug 6, 2024
34dbab0
Some tests fixed
afxgroup Aug 8, 2024
17cfac2
Remove unneeded assertion, because are valid input parameter
migthymax Aug 11, 2024
762818b
Remove unneeded assertion in fstat
migthymax Aug 11, 2024
32070c5
Merge pull request #200 from migthymax/beta10
afxgroup Aug 11, 2024
e9e712d
.unix file is checked using PROGDIR: otherwhise if you run the exe fr…
afxgroup Aug 11, 2024
195ad0e
Small poll.h changes to avoid clashes with some programs on signals f…
afxgroup Aug 12, 2024
bbe1618
Added _POSIX_VERSION was missing in unistd.h
afxgroup Aug 13, 2024
7b070d7
Added _POSIX_VERSION in sysconf
afxgroup Aug 13, 2024
952dec8
Added _SC_VERSION in unistd.h
afxgroup Aug 13, 2024
5146425
Small code cleaning
afxgroup Aug 14, 2024
51ed84e
Renamed (and fixed) clib4 terminfo files
afxgroup Aug 15, 2024
8e5c800
Fixed previously wrong buffer mode set on setbuf when no buffer is re…
afxgroup Aug 16, 2024
49b8fe1
Children is inserted into list when process is created and from child…
afxgroup Aug 16, 2024
848be52
Reverted ancient console readin on STDIO files.
afxgroup Aug 16, 2024
99bdd4c
Merge branch 'beta10' of github.com:AmigaLabs/clib4 into beta10
afxgroup Aug 16, 2024
a35c1c8
Fix for TERM settings
afxgroup Aug 16, 2024
e46b82f
Some Printf was in tgetent function
afxgroup Aug 16, 2024
ce5d41d
Added sigsuspend, so that posix (HAVE_POSIX) is correctly detected by…
migthymax Aug 17, 2024
dd68dc5
Updated debug function to work also when __clib4 is NULL.
afxgroup Aug 17, 2024
2106ced
main.c function doesn't use libc function anymore so startup is (way.…
afxgroup Aug 17, 2024
776b4eb
Check against DEBUG==1 on clib4.c
afxgroup Aug 17, 2024
ab756d8
Fixed slot assignment for sigsupend
migthymax Aug 18, 2024
793624f
Added test program for sigsupend
migthymax Aug 18, 2024
9e4ed3b
Merge pull request #202 from migthymax/beta10
afxgroup Aug 18, 2024
5b2607c
Added a SHOWMSG after and before pause() call in sigsuspend
afxgroup Aug 18, 2024
0a33c2f
fix for spawnedProcessEnter was causing an NPE. usergroup.library now…
afxgroup Aug 23, 2024
597ed91
Reworked fd and stdio locks on some function could cause deadlocks
afxgroup Aug 23, 2024
fa57195
Added sigpause, sigwait and spawnve
afxgroup Aug 23, 2024
9855dab
fix NPE on __environment caused by using malloc and not clearing memo…
afxgroup Aug 25, 2024
6ce59c5
Patches to get waitpid to return the correct return status.
elfpipe Aug 27, 2024
66ae458
Adjust spawnvpe to use same entry code as other spawning functions. T…
elfpipe Aug 27, 2024
e37f880
Reducing unnecessary uncommented code.
elfpipe Aug 27, 2024
b972b0c
Comment out printf statements in spawnvpe.c
elfpipe Aug 27, 2024
dbee830
Remove all reference to spawnvpe_callback (=obsolete).
elfpipe Aug 28, 2024
d578533
Merge pull request #204 from alfkil/beta10
afxgroup Aug 28, 2024
da8ac1b
Revert "Reverted ancient console readin on STDIO files."
afxgroup Aug 28, 2024
52bb6ef
Close usergroup library when done on children.c. Replaced some DebugP…
afxgroup Aug 28, 2024
a828a7d
Wrong revert on console_fdhookentry.c
afxgroup Aug 28, 2024
2bedab6
Fix return code for spawnvpe/waitpid.
elfpipe Aug 31, 2024
791585c
Merge pull request #205 from alfkil/beta10
afxgroup Aug 31, 2024
51412e0
Revert initializer to 0 instead of EOF (stdio/fwrite.c). Fixes proble…
elfpipe Sep 1, 2024
bc91bc1
Merge pull request #206 from alfkil/beta10
afxgroup Sep 1, 2024
a8826dc
When enable/disable unix paths at runtime set current path in a valid…
afxgroup Sep 11, 2024
b1639eb
Small changes to fix ncurses library.
afxgroup Sep 11, 2024
6fcc386
Small changes to fix ncurses library and make readline works correctly.
afxgroup Sep 14, 2024
7f18624
Fix popen/pclose and add test for popen.
elfpipe Sep 14, 2024
6c46112
Delete executables from popen test folder.
elfpipe Sep 14, 2024
0aafea3
Merge pull request #207 from alfkil/beta10
afxgroup Sep 14, 2024
fa608fa
FILE was not declared via #include <stdio.h>
afxgroup Sep 15, 2024
0c0c4e3
Comment aaway unnecessary checks for _POSIX_ARG_MAX in spawning funct…
elfpipe Sep 25, 2024
2aabdbc
Merge branch 'AmigaLabs:beta10' into beta10
elfpipe Sep 25, 2024
c900807
Merge pull request #209 from elfpipe/beta10
afxgroup Sep 25, 2024
2715e37
Calling GetVar inside libOpen cause a problem on exe file when progra…
afxgroup Oct 18, 2024
28fd8fc
WE CANNOT cakk DOS functions inside libOpen!
afxgroup Oct 19, 2024
4983e54
Don't lock memory if we call __malloc_r/__free_r since they lock the …
afxgroup Oct 22, 2024
7579fcb
wof_realloc already do all tests we do in realloc function
afxgroup Oct 22, 2024
932dd1f
ASOT_ITEMPOOL was not freed in fallback clib4 in reent_exit
afxgroup Oct 23, 2024
1168258
Changed memory allocator to wmem from WireShark project
afxgroup Oct 23, 2024
489292f
Small #define changes
afxgroup Oct 24, 2024
48572f6
Merge pull request #213 from AmigaLabs/wmem
afxgroup Nov 13, 2024
d99ab22
Merge branch 'master' into development
walkero-gr Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 6 additions & 3 deletions GNUmakefile.os4
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ WARNINGS := \
-Wundef -Wmissing-declarations -Wunused -Wwrite-strings -Wno-unused-value -Wno-comment -Wno-missing-braces \
-Wno-deprecated-declarations -Wno-sign-compare -Wno-unused-variable -Wno-parentheses -Wno-missing-prototypes \
-Wstrict-aliasing -Wno-shadow -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing \
-Wno-type-limits -Wno-cast-function-type -Wno-frame-address -Werror \
-Wno-type-limits -Wno-cast-function-type -Wno-frame-address -Wno-error=unused-but-set-variable -Werror \
# -Wbad-function-cast -Wconversion -Wformat

PIC := -fPIC -DPIC
Expand Down Expand Up @@ -106,7 +106,8 @@ INCLUDES := -I$(LIB_DIR)/include \
-I$(LIB_DIR)/termios \
-I$(LIB_DIR)/time \
-I$(LIB_DIR)/unistd \
-I$(LIB_DIR)/wchar
-I$(LIB_DIR)/wchar \
-I$(LIB_DIR)/wmem

SHARED := $(if $(SHARED),$(SHARED),yes)
STATIC := $(if $(STATIC),$(STATIC),yes)
Expand Down Expand Up @@ -139,6 +140,8 @@ ifdef SPE
-fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels -fno-inline-small-functions \
-fno-indirect-inlining -Wno-overflow -Wno-unused-but-set-variable -Wno-uninitialized #-Wdouble-promotion
AFLAGS := $(AFLAGS) -mvrsave -D__SPE__ -mspe -mtune=8540 -mcpu=8540 -mfloat-gprs=double $(CMATH) -Wno-overflow
CFLAGS := $(filter-out -Wno-cast-function-type, $(CFLAGS))
CFLAGS_N := $(filter-out -Wno-cast-function-type, $(CFLAGS_N))
endif

ifdef PROFILE
Expand Down Expand Up @@ -362,7 +365,7 @@ endef
define COMPILE_ALTIVEC_REG
$(VERBOSE)@$(MAKEDIR) $(@D)
$(VERBOSE)echo -e "\rAssembling altivec \033[0;33m[$(@D)]\033[0m \r\t\t\t\t\t\t\t\t\t\t\t \033[0;31m$(@F)\033[0m"
$(VERBOSE)$(CC) -maltivec -mabi=altivec -mvrsave -mregnames -DVRSAVE -o $@ -c $< $(LOG_COMMAND)
$(VERBOSE)$(CC) -maltivec -mabi=altivec -mcpu=7450 -mtune=7450 -falign-loops=16 -falign-functions=16 -falign-labels=16 -falign-jumps=16 -mvrsave -mregnames -DVRSAVE -o $@ -c $< $(LOG_COMMAND)
endef

define COMPILE_SPE_REG
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ have problems running existent software!

### New memory allocator

Clib4 now use `Wheel Of Fortune` allocator that is faster than previous one, and it seems more robust and with a cleaner
and portable code
Clib4 now use `wmem` allocator from WireShark that is faster than previous one, and it seems more robust and with a cleaner
and portable code.
You can choose at runtime (for test purpose) which kind of allocators want to use setting `CLIB4_MEMORY_ALLOCATOR` env variable.
At moment you can use:

| Value | Allocator |
|-------|---------------------------|
| 1 | WMEM_ALLOCATOR_SIMPLE |
| 2 | WMEM_ALLOCATOR_BLOCK |
| 3 | WMEM_ALLOCATOR_STRICT |
| 4 | WMEM_ALLOCATOR_BLOCK_FAST |

The default one is `WMEM_ALLOCATOR_BLOCK_STRICT`. `WMEM_ALLOCATOR_BLOCK_FAST` can crash on some situation. Please refer to `wmem/wmem_core.h` for all details.

### Optimized AMCC functions

Expand Down Expand Up @@ -219,6 +230,13 @@ constructors/destructors executions
- Try to use some functions/headers from https://github.com/attractivechaos/klib to improve speed
- Use a good locale implementation

### Libraries repository

A repository with pre packaged libraries is present and ready to use for debian like systems.
You can find all informations to the following <a href="https://github.com/AmigaLabs/clib4/wiki/Clib4-apt-packages-repository">wiki page</a>.

A list of packages can be found into public <a href="https://clib4pkg.amigasoft.net/ubuntu/dists/focal/main/binary-amd64/Packages">Packages</a> file.

## Legal status

Because this library is in part based upon free software it would be uncourteous not to make it free software itself.
Expand Down
39 changes: 34 additions & 5 deletions libc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ C_LOCALE := \
locale/setlocale.o

C_MISC := \
misc/children.o \
misc/map.o \
misc/uuid.o

Expand Down Expand Up @@ -159,7 +160,6 @@ C_POSIX := \
posix/getrlimit.o \
posix/setrlimit.o \
posix/getrusage.o \
posix/checkabort.o \
posix/kill.o \
posix/raise.o \
posix/sigaction.o \
Expand All @@ -171,8 +171,11 @@ C_POSIX := \
posix/sigismember.o \
posix/sigmask.o \
posix/signal.o \
posix/sigpause.o \
posix/sigprocmask.o \
posix/sigsuspend.o \
posix/sigsetmask.o \
posix/sigwait.o \
posix/statvfs.o \
posix/sysinfo.o \
posix/sysv_ftok.o \
Expand All @@ -195,6 +198,9 @@ C_POSIX := \
posix/sysv_shmids.o \
posix/ulimit.o \
posix/readv.o \
wait/wait.o \
wait/waitpid.o \
posix/waitpoll.o \
posix/writev.o \
posix/uname.o

Expand Down Expand Up @@ -420,7 +426,6 @@ C_STDIO := \
stdio/iobhookentry.o \
stdio/lock.o \
stdio/openiob.o \
stdio/parent_of_fh.o \
stdio/perror.o \
stdio/popen.o \
stdio/printf.o \
Expand Down Expand Up @@ -544,8 +549,7 @@ C_STDLIB := \
stdlib/udivsi4.o \
stdlib/umodsi3.o \
stdlib/unsetenv.o \
stdlib/valloc.o \
stdlib/wof_allocator.o
stdlib/valloc.o

C_STRING := \
string/strings_ffs.o \
Expand Down Expand Up @@ -576,12 +580,15 @@ C_STRING := \
cpu/4xx/strlen440.o \
cpu/4xx/strncmp440.o \
cpu/4xx/strrchr440.o \
cpu/altivec/vec_memchr.o \
cpu/altivec/vec_memcmp.o \
cpu/altivec/vec_memcpy.o \
cpu/altivec/vec_memset.o \
cpu/altivec/vec_strchr.o \
cpu/altivec/vec_strcpy.o \
cpu/generic/bcopy.o \
cpu/generic/strcat.o \
cpu/generic/strchr.o \
cpu/generic/strcpy.o \
cpu/generic/strlen.o \
string/rindex.o \
Expand Down Expand Up @@ -620,6 +627,7 @@ C_STRING := \
string/strxfrm.o

C_TERMCAP := \
termcap/tcstubs.o \
termcap/termcap.o \
termcap/tparam.o

Expand Down Expand Up @@ -754,7 +762,9 @@ C_UNISTD := \
unistd/setlogin.o \
unistd/sleep.o \
unistd/spawnv.o \
unistd/spawnve.o \
unistd/spawnvp.o \
unistd/spawnvpe.o \
unistd/strip_double_slash.o \
unistd/symlink.o \
unistd/sync_fd.o \
Expand All @@ -764,6 +774,7 @@ C_UNISTD := \
unistd/translatea2u.o \
unistd/translaterel.o \
unistd/translateu2a.o \
unistd/search_command_path.o \
unistd/truncate.o \
unistd/truncate64.o \
unistd/ttyname.o \
Expand Down Expand Up @@ -911,6 +922,23 @@ C_WCHAR := \
wchar/wctrans.o \
wchar/wctype.o

C_WMEM := \
wmem/wmem_allocator_block.o \
wmem/wmem_allocator_block_fast.o \
wmem/wmem_allocator_simple.o \
wmem/wmem_allocator_strict.o \
wmem/wmem_array.o \
wmem/wmem_core.o \
wmem/wmem_interval_tree.o \
wmem/wmem_list.o \
wmem/wmem_map.o \
wmem/wmem_miscutl.o \
wmem/wmem_multimap.o \
wmem/wmem_stack.o \
wmem/wmem_strutl.o \
wmem/wmem_tree.o \
wmem/wmem_user_cb.o

ifdef SPE
$(info Adding SPE objects)
C_STRING := $(C_STRING) \
Expand Down Expand Up @@ -957,7 +985,8 @@ C_LIBRARY := \
$(C_TIME) \
$(C_UNISTD) \
$(C_USERGROUP) \
$(C_WCHAR)
$(C_WCHAR) \
$(C_WMEM)

C_LIB := \
c.lib_rev.o \
Expand Down
14 changes: 5 additions & 9 deletions library/argz/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,30 @@
#include <argz.h>

error_t
argz_create(char *const argv[], char **argz, size_t *argz_len)
{
argz_create(char *const argv[], char **argz, size_t *argz_len) {
int argc = 0;
int i = 0;
size_t len = 0;
char *iter;

*argz_len = 0;

if (*argv == NULL)
{
if (*argv == NULL) {
*argz = NULL;
return 0;
}

while (argv[argc])
{
while (argv[argc]) {
*argz_len += (strlen(argv[argc]) + 1);
argc++;
}

/* There are argc strings to copy into argz. */
if (!(*argz = (char *)malloc(*argz_len)))
if (!(*argz = (char *) malloc(*argz_len)))
return ENOMEM;

iter = *argz;
for (i = 0; i < argc; i++)
{
for (i = 0; i < argc; i++) {
len = strlen(argv[i]) + 1;
memcpy(iter, argv[i], len);
iter += len;
Expand Down
30 changes: 12 additions & 18 deletions library/argz/create_sep.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,34 @@
#include <argz.h>

error_t
argz_create_sep(const char *string, int sep, char **argz, size_t *argz_len)
{
size_t len = 0;
int i = 0;
argz_create_sep(const char *string, int sep, char **argz, size_t *argz_len) {
size_t len;
int i;
int num_strings = 0;
char delim[2];
char *running = 0;
char *old_running = 0;
char *token = 0;
char *iter = 0;
char *running;
char *old_running;
char *token;
char *iter;

delim[0] = (char) sep;
delim[1] = '\0';

running = strdup(string);

if(!running)
{
if (!running) {
return ENOMEM;
}

old_running = running;

while ((token = strsep(&running, delim)))
{
while ((token = strsep(&running, delim))) {
len = strlen(token);
*argz_len += (len + 1);
num_strings++;
}

if (!(*argz = (char *)malloc(*argz_len)))
{
if (!(*argz = (char *) malloc(*argz_len))) {
free(old_running);
return ENOMEM;
}
Expand All @@ -49,17 +45,15 @@ argz_create_sep(const char *string, int sep, char **argz, size_t *argz_len)

running = strdup(string);

if(!running)
{
if (!running) {
free(*argz);
return ENOMEM;
}

old_running = running;

iter = *argz;
for (i = 0; i < num_strings; i++)
{
for (i = 0; i < num_strings; i++) {
token = strsep(&running, delim);
len = strlen(token) + 1;
memcpy(iter, token, len);
Expand Down
13 changes: 5 additions & 8 deletions library/argz/delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@
#include <argz.h>

error_t
argz_delete(char **argz, size_t *argz_len, char *entry)
{
argz_delete(char **argz, size_t *argz_len, char *entry) {
size_t len = 0;
char *moveto = entry;

if (entry)
{
if (entry) {
len = strlen(entry) + 1;
entry += len;

memmove(moveto, entry, (size_t) (*argz + *argz_len - entry));
memmove(moveto, entry, (size_t)(*argz + *argz_len - entry));

*argz_len -= len;

if (!(*argz = (char *)realloc(*argz, *argz_len)))
if (!(*argz = (char *) realloc(*argz, *argz_len)))
return ENOMEM;

if (*argz_len <= 0)
{
if (*argz_len <= 0) {
free(*argz);
*argz = NULL;
}
Expand Down
Loading
Loading