Fix basename() and dirname()

This commit is contained in:
Justine Tunney 2022-04-06 00:13:44 -07:00
parent 9b11206ae3
commit 04d39d47f1
41 changed files with 489 additions and 207 deletions

View file

@ -17,11 +17,12 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/runtime/gc.internal.h"
#include "libc/x/x.h"
/**
* Returns directory portion of path.
*/
char *xdirname(const char *path) {
return dirname(xstrdup(path));
return xstrdup(dirname(gc(xstrdup(path))));
}

View file

@ -23,10 +23,10 @@
/**
* Reads line from stream.
*
* @return allocated line that needs free() and usually chomp() too,
* @return allocated line that needs free() and usually _chomp() too,
* or NULL on ferror() or feof()
* @see getdelim() for a more difficult api
* @see chomp()
* @see _chomp()
*/
char *xgetline(FILE *f) {
char *p;

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/str/path.h"
#include "libc/str/str.h"
#include "libc/x/x.h"