Commit 29555d72 authored by Jonas Termansen's avatar Jonas Termansen

Fix <fcntl.h> including <sys/stat.h> namespace pollution.

POSIX allows <fcntl.h> to include <sys/stat.h>, but doesn't require it.
There's little reason to do that, since they are separate headers, and
<fcntl.h> just needs the mode_t constants. Fix the code accidentally
relying on <fcntl.h> including <sys/stat.h>. The mode_t constants are now
provided in their own kernel header <sortix/mode.h>.

Additionally fix <sys/stat.h> pulling in all of <sys/types.h>, which is not
allowed by POSIX, which only requires a few types to be declared. Fix the
code accidentally relying on <sys/stat.h> including <sys/types.h>.

Finally fix <dirent.h> pulling in <stdint.h> through <sortix/dirent.h>.

The <sortix/__/dt.h> and <sortix/__/stat.h> headers are no longer required
and their contents have been merged into <sortix/__/dirent.h>.
parent 9c3af039
/*
* 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 <sys/stat.h>
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
......
/*
* 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 <sys/cdefs.h>
#include <sortix/__/dt.h>
#include <sortix/__/stat.h>
#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
/*
* 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 <sys/cdefs.h>
#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
/*
* 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 <sys/__/types.h>
#include <stdint.h>
#include <sortix/__/dirent.h>
#include <sortix/__/dt.h>
#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
/*
* Copyright (c) 2012, 2013, 2014 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
......@@ -13,27 +13,54 @@
* 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.
* sortix/mode.h
* Defines the symbolic constants for use in mode_t.
*/
#ifndef INCLUDE_SORTIX____STAT_H
#define INCLUDE_SORTIX____STAT_H
#ifndef INCLUDE_SORTIX_MODE_H
#define INCLUDE_SORTIX_MODE_H
#include <sys/cdefs.h>
#include <sortix/__/dt.h>
#include <sortix/__/dirent.h>
#ifdef __cplusplus
extern "C" {
#endif
#define __S_IFMT_SHIFT 12
#define __S_IFMT_MASK __DT_BITS
#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 __cplusplus
} /* extern "C" */
#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
/*
* 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 <sys/cdefs.h>
#include <sys/types.h>
#include <sortix/__/dirent.h>
#include <sortix/__/dt.h>
#include <sortix/__/stat.h>
#include <sys/__/types.h>
#include <sortix/mode.h>
#include <sortix/timespec.h>
#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
/*
* 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 <sys/cdefs.h>
#include <sys/__/types.h>
#include <sortix/dirent.h>
#if defined(__is_sortix_libc)
......
/*
* 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 <sys/__/types.h>
#include <sys/stat.h>
#include <sortix/fcntl.h>
#include <sortix/seek.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <sortix/mode.h>
/* 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, ...);
......
......@@ -21,6 +21,7 @@
#define INCLUDE_FSMARSHALL_MSG_H
#include <sys/cdefs.h>
#include <sys/types.h>
#include <stddef.h>
......
/*
* 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 <sys/__/types.h>
#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 <sortix/timespec.h>
#include <sortix/stat.h>
#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 <sortix/timespec.h>
#include <sortix/stat.h>
#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);
......
/*
* 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 <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
......
/*
* 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 <sys/termmode.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
......
/*
* 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 <sys/stat.h>
#include <sys/types.h>
#include <err.h>
......
/*
* 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 <sys/stat.h>
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
......
......@@ -19,6 +19,7 @@
#include <sys/display.h>
#include <sys/keycodes.h>
#include <sys/stat.h>
#include <sys/termmode.h>
#include <sys/wait.h>
......
/*
* 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 <sys/stat.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdio.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment