Author | Jamozed <[email protected]> |
Date | 2020-06-26 10:33:17 |
Commit | 4e723d65558e4ee97508ae95617ba2b080577f34 |
Parent | dee294962682641c95ba447b4f9e5acceb5c6195 |
logname: Add POSIX logname
Diffstat
M | CMakeLists.txt | | | 1 | + |
M | README.md | | | 7 | ++++--- |
A | man/logname.1 | | | 24 | ++++++++++++++++++++++++ |
A | src/logname.c | | | 33 | +++++++++++++++++++++++++++++++++ |
4 files changed, 62 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9832ae3..aae602b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ ADD_EXECUTABLE(dirname ${CMAKE_SOURCE_DIR}/src/dirname.c) ADD_EXECUTABLE(echo ${CMAKE_SOURCE_DIR}/src/echo.c) ADD_EXECUTABLE(false ${CMAKE_SOURCE_DIR}/src/false.c) ADD_EXECUTABLE(link ${CMAKE_SOURCE_DIR}/src/link.c) +ADD_EXECUTABLE(logname ${CMAKE_SOURCE_DIR}/src/logname.c) ADD_EXECUTABLE(mkdir ${CMAKE_SOURCE_DIR}/src/mkdir.c) ADD_EXECUTABLE(rmdir ${CMAKE_SOURCE_DIR}/src/rmdir.c) ADD_EXECUTABLE(tee ${CMAKE_SOURCE_DIR}/src/tee.c) diff --git a/README.md b/README.md index e913ffd..496bfca 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# OMKOV Core Utilities +# OMKOV coreutils > OMKOV implementations of core software utilities -OMKOV Core Utilities (coreutils) implements many basic software utilities -commonly found on UNIX-like systems. +OMKOV coreutils implements many basic software utilities commonly found on +UNIX-like systems. ## Utilities @@ -15,6 +15,7 @@ commonly found on UNIX-like systems. | echo | Write arguments to standard output | POSIX | | false | Return false value | POSIX | | link | Create a link to a file | POSIX | +| logname | Return the user's login name | POSIX | | mkdir | Make directories | POSIX | | rmdir | Remove directories | POSIX | | tee | Duplicate standard input | POSIX | diff --git a/man/logname.1 b/man/logname.1 new file mode 100644 index 0000000..91b23bb --- /dev/null +++ b/man/logname.1 @@ -0,0 +1,24 @@ +.TH LOGNAME 1 2020-06-26 "OMKOV coreutils" "General Commands Manual" +.SH NAME +logname \(em return the user's login name +.SH SYNOPSYS +\fBlogname\fR +.SH DESCRIPTION +Print the user's login name to standard output. +.SH EXIT STATUS +The following exit values will be returned: +.TP +\ 0 +Successful completion. +.TP +>0 +An error occurred. +.SH STANDARDS +The \fIlogname\fR utility is compliant with the IEEE Std 1003.2-1992 ("POSIX.2") +specification. +.SH COPYRIGHT +.nf +Copyright (C) 2020, Jakob Wakeling +All rights reserved. +OMKOV Public Domain Licence (https://www.omkov.net/OLPD) +.fi diff --git a/src/logname.c b/src/logname.c new file mode 100644 index 0000000..ed4f2cb --- /dev/null +++ b/src/logname.c @@ -0,0 +1,33 @@ +// logname.c, version 1.0.0 +// OMKOV coreutils implementation of POSIX logname +// Copyright (C) 2020, Jakob Wakeling +// All rights reserved. + +/* +OMKOV Public Domain Licence, version 1.0 + +Permission is hereby granted to deal with this software and its associated +documentation files without restriction. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. +*/ + +#include "error.h" + +#include <unistd.h> + +#include <errno.h> +#include <stdio.h> +#include <string.h> + +int main(int argc, char *argv[]) { (void)argc; + register char *login = getlogin(); + if (!login) { error(1, "%s: %s", argv[0], serrno); } + else { fputs(login, stdout); fputc('\n', stdout); } + return 0; +}