From 29555d72bb46a890e0e00660f1760c5660c26b26 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 14 Jul 2018 22:34:48 +0200 Subject: [PATCH] Fix including namespace pollution. POSIX allows to include , but doesn't require it. There's little reason to do that, since they are separate headers, and just needs the mode_t constants. Fix the code accidentally relying on including . The mode_t constants are now provided in their own kernel header . Additionally fix pulling in all of , which is not allowed by POSIX, which only requires a few types to be declared. Fix the code accidentally relying on including . Finally fix pulling in through . The and headers are no longer required and their contents have been merged into . --- ext/inode.cpp | 4 +- kernel/include/sortix/__/dirent.h | 22 +++---- kernel/include/sortix/__/dt.h | 43 -------------- kernel/include/sortix/__/stat.h | 39 ------------- kernel/include/sortix/dirent.h | 13 +---- kernel/include/sortix/mode.h | 66 +++++++++++++++++++++ kernel/include/sortix/stat.h | 95 +++++++++++++++---------------- libc/include/dirent.h | 4 +- libc/include/fcntl.h | 23 +++++--- libc/include/fsmarshall-msg.h | 1 + libc/include/sys/stat.h | 67 +++------------------- libc/stdlib/mkdtemps.c | 5 +- login/login.c | 3 +- sysinstall/manifest.c | 3 +- sysinstall/sysmerge.c | 4 +- trianglix/trianglix.cpp | 1 + utils/ln.c | 5 +- 17 files changed, 166 insertions(+), 232 deletions(-) delete mode 100644 kernel/include/sortix/__/dt.h delete mode 100644 kernel/include/sortix/__/stat.h create mode 100644 kernel/include/sortix/mode.h diff --git a/ext/inode.cpp b/ext/inode.cpp index 5c4703aa..6d168305 100644 --- a/ext/inode.cpp +++ b/ext/inode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2014, 2015, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,11 +21,13 @@ #define __STDC_LIMIT_MACROS #include +#include #include #include #include #include +#include #include #include #include diff --git a/kernel/include/sortix/__/dirent.h b/kernel/include/sortix/__/dirent.h index f9ec4b87..68afbc25 100644 --- a/kernel/include/sortix/__/dirent.h +++ b/kernel/include/sortix/__/dirent.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, 2014 Jonas 'Sortie' Termansen. + * Copyright (c) 2012, 2013, 2014, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -22,18 +22,20 @@ #include -#include -#include +#define __DT_UNKNOWN 0x0 +#define __DT_FIFO 0x1 +#define __DT_CHR 0x2 +#define __DT_DIR 0x4 +#define __DT_BLK 0x6 +#define __DT_REG 0x8 +#define __DT_LNK 0xA +#define __DT_SOCK 0xC +#define __DT_BITS 0xF -#ifdef __cplusplus -extern "C" { -#endif +#define __S_IFMT_SHIFT 12 +#define __S_IFMT_MASK __DT_BITS #define __IFTODT(mode) (((mode) & __S_IFMT) >> __S_IFMT_SHIFT) #define __DTTOIF(dirtype) ((dirtype) << __S_IFMT_SHIFT) -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif diff --git a/kernel/include/sortix/__/dt.h b/kernel/include/sortix/__/dt.h deleted file mode 100644 index be45da45..00000000 --- a/kernel/include/sortix/__/dt.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 2014 Jonas 'Sortie' Termansen. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * sortix/__/dt.h - * Defines the values for the d_type field. - */ - -#ifndef INCLUDE_SORTIX____DT_H -#define INCLUDE_SORTIX____DT_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define __DT_UNKNOWN 0x0 -#define __DT_FIFO 0x1 -#define __DT_CHR 0x2 -#define __DT_DIR 0x4 -#define __DT_BLK 0x6 -#define __DT_REG 0x8 -#define __DT_LNK 0xA -#define __DT_SOCK 0xC -#define __DT_BITS 0xF - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/kernel/include/sortix/__/stat.h b/kernel/include/sortix/__/stat.h deleted file mode 100644 index 62607498..00000000 --- a/kernel/include/sortix/__/stat.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 2014 Jonas 'Sortie' Termansen. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * sortix/__/stat.h - * Defines the struct stat used for file meta-information and other useful - * macros and values relating to values stored in it. - */ - -#ifndef INCLUDE_SORTIX____STAT_H -#define INCLUDE_SORTIX____STAT_H - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define __S_IFMT_SHIFT 12 -#define __S_IFMT_MASK __DT_BITS - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/kernel/include/sortix/dirent.h b/kernel/include/sortix/dirent.h index 97136112..c38ea4b2 100644 --- a/kernel/include/sortix/dirent.h +++ b/kernel/include/sortix/dirent.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2012, 2014, 2015, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,14 +24,7 @@ #include -#include - #include -#include - -#ifdef __cplusplus -extern "C" { -#endif #ifndef __dev_t_defined #define __dev_t_defined @@ -75,8 +68,4 @@ struct dirent __extension__ char d_name[]; }; -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif diff --git a/kernel/include/sortix/mode.h b/kernel/include/sortix/mode.h new file mode 100644 index 00000000..0c26396d --- /dev/null +++ b/kernel/include/sortix/mode.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012-2018 Jonas 'Sortie' Termansen. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * sortix/mode.h + * Defines the symbolic constants for use in mode_t. + */ + +#ifndef INCLUDE_SORTIX_MODE_H +#define INCLUDE_SORTIX_MODE_H + +#include + +#include + +#define S_IXOTH 01 +#define S_IWOTH 02 +#define S_IROTH 04 +#define S_IRWXO 07 +#define S_IXGRP 010 +#define S_IWGRP 020 +#define S_IRGRP 040 +#define S_IRWXG 070 +#define S_IXUSR 0100 +#define S_IWUSR 0200 +#define S_IRUSR 0400 +#define S_IRWXU 0700 +#define S_IFMT __DTTOIF(__DT_BITS) +#define S_IFSOCK __DTTOIF(__DT_SOCK) +#define S_IFLNK __DTTOIF(__DT_LNK) +#define S_IFREG __DTTOIF(__DT_REG) +#define S_IFBLK __DTTOIF(__DT_BLK) +#define S_IFDIR __DTTOIF(__DT_DIR) +#define S_IFCHR __DTTOIF(__DT_CHR) +#define S_IFIFO __DTTOIF(__DT_FIFO) +#define S_ISUID 0x0800 +#define S_ISGID 0x0400 +#define S_ISVTX 0x0200 +#define S_SETABLE (0777 | 0x0200 | 0x0400 | 0x0800) +#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) +#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) + +#ifdef __is_sortix_kernel +/* Run the factory method on the inode when opened to get the real file. */ +#define S_IFFACTORY 0x10000 +/* Don't run the factory method if simply stat'ing the inode. */ +#define S_IFFACTORY_NOSTAT 0x20000 +#endif + +#endif diff --git a/kernel/include/sortix/stat.h b/kernel/include/sortix/stat.h index 1a05138b..3ca13781 100644 --- a/kernel/include/sortix/stat.h +++ b/kernel/include/sortix/stat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen. + * Copyright (c) 2012-2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,16 +23,54 @@ #include -#include - -#include -#include -#include +#include +#include #include -#ifdef __cplusplus -extern "C" { +#ifndef __dev_t_defined +#define __dev_t_defined +typedef __dev_t dev_t; +#endif + +#ifndef __ino_t_defined +#define __ino_t_defined +typedef __ino_t ino_t; +#endif + +#ifndef __mode_t_defined +#define __mode_t_defined +typedef __mode_t mode_t; +#endif + +#ifndef __nlink_t_defined +#define __nlink_t_defined +typedef __nlink_t nlink_t; +#endif + +#ifndef __uid_t_defined +#define __uid_t_defined +typedef __uid_t uid_t; +#endif + +#ifndef __gid_t_defined +#define __gid_t_defined +typedef __gid_t gid_t; +#endif + +#ifndef __off_t_defined +#define __off_t_defined +typedef __off_t off_t; +#endif + +#ifndef __blksize_t_defined +#define __blksize_t_defined +typedef __blksize_t blksize_t; +#endif + +#ifndef __blkcnt_t_defined +#define __blkcnt_t_defined +typedef __blkcnt_t blkcnt_t; #endif struct stat @@ -52,48 +90,7 @@ struct stat blkcnt_t st_blocks; }; -#define S_IXOTH 01 -#define S_IWOTH 02 -#define S_IROTH 04 -#define S_IRWXO 07 -#define S_IXGRP 010 -#define S_IWGRP 020 -#define S_IRGRP 040 -#define S_IRWXG 070 -#define S_IXUSR 0100 -#define S_IWUSR 0200 -#define S_IRUSR 0400 -#define S_IRWXU 0700 -#define S_IFMT __DTTOIF(__DT_BITS) -#define S_IFSOCK __DTTOIF(__DT_SOCK) -#define S_IFLNK __DTTOIF(__DT_LNK) -#define S_IFREG __DTTOIF(__DT_REG) -#define S_IFBLK __DTTOIF(__DT_BLK) -#define S_IFDIR __DTTOIF(__DT_DIR) -#define S_IFCHR __DTTOIF(__DT_CHR) -#define S_IFIFO __DTTOIF(__DT_FIFO) -#define S_ISUID 0x0800 -#define S_ISGID 0x0400 -#define S_ISVTX 0x0200 -#define S_SETABLE (0777 | 0x0200 | 0x0400 | 0x0800) -#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) -#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) -#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) -#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) - -#ifdef __is_sortix_kernel -#define S_IFFACTORY 0x10000 -#define S_IFFACTORY_NOSTAT 0x20000 -#endif - #define UTIME_NOW 0x3FFFFFFF #define UTIME_OMIT 0x3FFFFFFE -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif diff --git a/libc/include/dirent.h b/libc/include/dirent.h index 1eb70586..fbf9c059 100644 --- a/libc/include/dirent.h +++ b/libc/include/dirent.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -22,8 +22,6 @@ #include -#include - #include #if defined(__is_sortix_libc) diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h index f23b1749..6497f39a 100644 --- a/libc/include/fcntl.h +++ b/libc/include/fcntl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2012, 2013, 2014, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,14 +24,9 @@ #include -#include - #include #include - -#ifdef __cplusplus -extern "C" { -#endif +#include /* The kernel would like to simply deal with one bit for each base access mode, but using the traditional names O_RDONLY, O_WRONLY and O_RDWR for this would @@ -51,6 +46,20 @@ extern "C" { typedef __pid_t pid_t; #endif +#ifndef __off_t_defined +#define __off_t_defined +typedef __off_t off_t; +#endif + +#ifndef __mode_t_defined +#define __mode_t_defined +typedef __mode_t mode_t; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + int creat(const char* path, mode_t mode); int fcntl(int fd, int cmd, ...); int open(const char* path, int oflag, ...); diff --git a/libc/include/fsmarshall-msg.h b/libc/include/fsmarshall-msg.h index afe60554..f1ab958f 100644 --- a/libc/include/fsmarshall-msg.h +++ b/libc/include/fsmarshall-msg.h @@ -21,6 +21,7 @@ #define INCLUDE_FSMARSHALL_MSG_H #include +#include #include diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index 0af2ecc8..d01e2050 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,77 +24,24 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef __blkcnt_t_defined -#define __blkcnt_t_defined -typedef __blkcnt_t blkcnt_t; -#endif - -#ifndef __blksize_t_defined -#define __blksize_t_defined -typedef __blksize_t blksize_t; -#endif - -#ifndef __dev_t_defined -#define __dev_t_defined -typedef __dev_t dev_t; -#endif - -#ifndef __ino_t_defined -#define __ino_t_defined -typedef __ino_t ino_t; -#endif +#include +#include #ifndef __mode_t_defined #define __mode_t_defined typedef __mode_t mode_t; #endif -#ifndef __nlink_t_defined -#define __nlink_t_defined -typedef __nlink_t nlink_t; -#endif - -#ifndef __uid_t_defined -#define __uid_t_defined -typedef __uid_t uid_t; -#endif - -#ifndef __gid_t_defined -#define __gid_t_defined -typedef __gid_t gid_t; -#endif - -#ifndef __off_t_defined -#define __off_t_defined -typedef __off_t off_t; -#endif - -#ifndef __time_t_defined -#define __time_t_defined -typedef __time_t time_t; -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - /* POSIX mandates that we define these compatibility macros to support programs that are yet to embrace struct timespec. */ #define st_atime st_atim.tv_sec #define st_ctime st_ctim.tv_sec #define st_mtime st_mtim.tv_sec +#ifdef __cplusplus +extern "C" { +#endif + int chmod(const char* path, mode_t mode); int fchmod(int fd, mode_t mode); int fchmodat(int dirfd, const char* path, mode_t mode, int flags); diff --git a/libc/stdlib/mkdtemps.c b/libc/stdlib/mkdtemps.c index e0dc327c..ae6be1f3 100644 --- a/libc/stdlib/mkdtemps.c +++ b/libc/stdlib/mkdtemps.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2014, 2015, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,8 +17,9 @@ * Make a unique temporary directory path and create it. */ +#include + #include -#include #include #include diff --git a/login/login.c b/login/login.c index f5cc8a9e..f3831280 100644 --- a/login/login.c +++ b/login/login.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2014, 2015, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,6 +18,7 @@ */ #include +#include #include #include diff --git a/sysinstall/manifest.c b/sysinstall/manifest.c index 6ba96b21..21623a03 100644 --- a/sysinstall/manifest.c +++ b/sysinstall/manifest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016 Jonas 'Sortie' Termansen. + * Copyright (c) 2015, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,6 +17,7 @@ * Manifest handling functions. */ +#include #include #include diff --git a/sysinstall/sysmerge.c b/sysinstall/sysmerge.c index 1eff27be..36e9abca 100644 --- a/sysinstall/sysmerge.c +++ b/sysinstall/sysmerge.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Jonas 'Sortie' Termansen. + * Copyright (c) 2016, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,11 +17,11 @@ * Upgrade current operating system from a sysroot. */ +#include #include #include #include -#include #include #include #include diff --git a/trianglix/trianglix.cpp b/trianglix/trianglix.cpp index 417cc297..966e526f 100644 --- a/trianglix/trianglix.cpp +++ b/trianglix/trianglix.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/utils/ln.c b/utils/ln.c index 9f9fc43a..46a42eae 100644 --- a/utils/ln.c +++ b/utils/ln.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2018 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,9 +17,10 @@ * Create a hard or symbolic link. */ +#include + #include #include -#include #include #include #include