userspace: Implement `dirname` utility
This commit is contained in:
parent
097ab82529
commit
cb7d5c9d09
|
@ -7,6 +7,7 @@ set(USERSPACE_PROGRAMS
|
|||
cp
|
||||
dd
|
||||
dhcp-client
|
||||
dirname
|
||||
DynamicLoader
|
||||
echo
|
||||
env
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(dirname ${SOURCES})
|
||||
banan_link_library(dirname libc)
|
||||
|
||||
install(TARGETS dirname OPTIONAL)
|
|
@ -0,0 +1,18 @@
|
|||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int usage(const char* argv0, int ret)
|
||||
{
|
||||
FILE* fout = ret ? stderr : stdout;
|
||||
fprintf(fout, "usage: %s STRING\n", argv0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
return usage(argv[0], 1);
|
||||
const char* result = dirname(const_cast<char*>(argv[1]));
|
||||
printf("%s\n", result);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue