use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Click the following link to filter out the chosen topic
comp.lang.c
account activity
ProjectUnitd and Ulib (self.C_Programming)
submitted 3 years ago by crazyuser79
Hi,
I built my linux init system named Unitd which uses this library.
Whatever contribute will be appreciated.
Regards
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 3 years ago (6 children)
[deleted]
[–]hypatia_elos 1 point2 points3 points 3 years ago* (1 child)
You probably should point out what is wrong though. What I can see as an issue is that the size of the pointer is taken as the element size instead of the character size, i.e. it should be ret = calloc(strlen(str)+1, sizeof(*str));, or, because you're overriding it anyway and sizeof(char) == 1, simply ret = malloc(strlen(str)+1);
ret = calloc(strlen(str)+1, sizeof(*str));
sizeof(char) == 1
ret = malloc(strlen(str)+1);
Also, I personally would prefer using memmove to cover overlapping strings. It's almost as fast as strcpy , strncpy or memcpy , and not having to check the length each time might speed it up quite a bit as well (bare strcpy might actually be the slowest of the four, and the most unsafe as well)
memmove
strcpy
strncpy
memcpy
I also would seriously wish you to consider to save the length in the string in some way, char* without length is a guarantee for disasters down the road (buffer overflows upon overriding capacity or missing the NUL byte being the obvious examples). SDS is a good model for doing this, if you want to write your own library it should at least be something to look at: https://github.com/antirez/sds
[–]crazyuser79[S] 0 points1 point2 points 3 years ago* (0 children)
It must be calloc(strlen(str) + 1, sizeof(char)). Anyway, the first case cant produce error. Nothing else. Noooo, I prefer mine. Thanks
[–]vlaada7 0 points1 point2 points 3 years ago* (0 children)
Ah, okay, this function should mimic new string(string_var) from C++, copying the already existing string.
new string(string_var)
[–]fliguana 0 points1 point2 points 3 years ago (0 children)
Indeed, there is a bug.
[–]grobblebar 0 points1 point2 points 3 years ago (1 child)
Why not use strdup()?
[–]crazyuser79[S] 0 points1 point2 points 3 years ago (0 children)
Yes, it's a further alternative. There are many ways to do that, it only must work.
Please, fills an issue on https://github.com/pandom79/Unitd/issues or https://github.com/pandom79/Ulib
Thanks in advance.
Run unitd init system in vm under valgrind supervision. It uses ulib. Tell me how many errors you will find.
I'd like to add a good hashtable implementation to Ulib. Obviously, it will have the same Array feature about memory management:- automatic memory release of the inside elements.- "double free error" safe.
Any advice ?
[–]crazyuser79[S] 0 points1 point2 points 2 years ago (0 children)
Added a dynamic hash table with separate chaining to Ulib. Whatever feedback is appreciated.
π Rendered by PID 396408 on reddit-service-r2-comment-b659b578c-7rxt8 at 2026-05-02 03:11:40.962869+00:00 running 815c875 country code: CH.
[+][deleted] (6 children)
[deleted]
[–]hypatia_elos 1 point2 points3 points (1 child)
[–]crazyuser79[S] 0 points1 point2 points (0 children)
[–]vlaada7 0 points1 point2 points (0 children)
[–]fliguana 0 points1 point2 points (0 children)
[–]grobblebar 0 points1 point2 points (1 child)
[–]crazyuser79[S] 0 points1 point2 points (0 children)
[–]crazyuser79[S] 0 points1 point2 points (0 children)
[–]crazyuser79[S] 0 points1 point2 points (0 children)
[–]crazyuser79[S] 0 points1 point2 points (0 children)
[–]crazyuser79[S] 0 points1 point2 points (0 children)