diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-07 22:15:33 -0600 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-07 22:15:33 -0600 |
commit | 7b1ef4aa3f0fbe0b0742a272327ba29325bd917c (patch) | |
tree | 67198cad1ec397a4c8ed35cc0535eb6e07d84a1e /owner | |
parent | d1b9110c038ed1e8d1e1fe2c959377f0a43706a2 (diff) | |
download | horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.tar.gz horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.tar.bz2 horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.tar.xz horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.zip |
owner: New utility
Diffstat (limited to 'owner')
-rw-r--r-- | owner/CMakeLists.txt | 6 | ||||
-rw-r--r-- | owner/owner.c | 30 |
2 files changed, 36 insertions, 0 deletions
diff --git a/owner/CMakeLists.txt b/owner/CMakeLists.txt new file mode 100644 index 0000000..961efe7 --- /dev/null +++ b/owner/CMakeLists.txt @@ -0,0 +1,6 @@ +set(OWNER_SRCS + owner.c +) +add_executable(hscript-printowner ${OWNER_SRCS}) + +install(TARGETS hscript-printowner DESTINATION bin) diff --git a/owner/owner.c b/owner/owner.c new file mode 100644 index 0000000..2540421 --- /dev/null +++ b/owner/owner.c @@ -0,0 +1,30 @@ +/* + * owner.c - Implementation of the "print file owner UID" utility + * Project Horizon + * + * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the NCSA license. + * + * SPDX-License-Identifier: NCSA + */ + +#include <stdio.h> /* fprintf, perror */ +#include <stdlib.h> /* EXIT_* */ +#include <sys/stat.h> /* stat(3) and friends */ + +int main(int argc, char *argv[]) { + if(argc != 2) { + fprintf(stderr, "hscript-printowner: requires a path or file\n"); + return EXIT_FAILURE; + } + + struct stat buf; + if(stat(argv[1], &buf) != 0) { + perror("hscript-printowner: stat"); + return EXIT_FAILURE; + } + + fprintf(stdout, "%d\n", buf.st_uid); + + return EXIT_SUCCESS; +} |