Changes in uspace/lib/posix/unistd.c [823a929:ec18957a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/unistd.c
r823a929 rec18957a 38 38 #include "internal/common.h" 39 39 #include "unistd.h" 40 #include <task.h> 40 41 #include "errno.h" 42 #include "string.h" 43 #include "fcntl.h" 44 45 #include "libc/task.h" 46 #include "libc/stats.h" 47 #include "libc/malloc.h" 41 48 42 49 /* Array of environment variable strings (NAME=VALUE). */ 43 char **environ = NULL; 44 45 /** 46 * Dummy function. Always returns false, because there is no easy way to find 47 * out under HelenOS. 48 * 49 * @param fd 50 * @return Always false. 50 char **posix_environ = NULL; 51 52 /** 53 * Get current user name. 54 * 55 * @return User name (static) string or NULL if not found. 56 */ 57 char *posix_getlogin(void) 58 { 59 /* There is currently no support for user accounts in HelenOS. */ 60 return (char *) "user"; 61 } 62 63 /** 64 * Get current user name. 65 * 66 * @param name Pointer to a user supplied buffer. 67 * @param namesize Length of the buffer. 68 * @return Zero on success, error code otherwise. 69 */ 70 int posix_getlogin_r(char *name, size_t namesize) 71 { 72 /* There is currently no support for user accounts in HelenOS. */ 73 if (namesize >= 5) { 74 posix_strcpy(name, (char *) "user"); 75 return 0; 76 } else { 77 errno = ERANGE; 78 return -1; 79 } 80 } 81 82 /** 83 * Test whether open file descriptor is associated with a terminal. 84 * 85 * @param fd Open file descriptor to test. 86 * @return Boolean result of the test. 51 87 */ 52 88 int posix_isatty(int fd) 53 89 { 90 /* Always returns false, because there is no easy way to find 91 * out under HelenOS. */ 54 92 return false; 55 93 } 56 94 57 95 /** 58 * 59 * @return 96 * Determine the page size of the current run of the process. 97 * 98 * @return Page size of the process. 60 99 */ 61 100 int posix_getpagesize(void) … … 65 104 66 105 /** 67 * 68 * @return 106 * Get the process ID of the calling process. 107 * 108 * @return Process ID. 69 109 */ 70 110 posix_pid_t posix_getpid(void) … … 74 114 75 115 /** 76 * 77 * @return 116 * Get the real user ID of the calling process. 117 * 118 * @return User ID. 78 119 */ 79 120 posix_uid_t posix_getuid(void) 80 121 { 81 // TODO 82 not_implemented(); 83 } 84 85 /** 86 * 87 * @return 122 /* There is currently no support for user accounts in HelenOS. */ 123 return 0; 124 } 125 126 /** 127 * Get the real group ID of the calling process. 128 * 129 * @return Group ID. 88 130 */ 89 131 posix_gid_t posix_getgid(void) 90 132 { 91 // TODO 92 not_implemented(); 93 } 94 95 /** 96 * 97 * @param path 98 * @param amode 99 * @return 133 /* There is currently no support for user accounts in HelenOS. */ 134 return 0; 135 } 136 137 /** 138 * Determine accessibility of a file. 139 * 140 * @param path File to check accessibility for. 141 * @param amode Either check for existence or intended access mode. 142 * @return Zero on success, -1 otherwise. 100 143 */ 101 144 int posix_access(const char *path, int amode) 102 145 { 103 // TODO 104 not_implemented(); 105 } 106 107 /** 108 * 109 * @param name 110 * @return 146 if (amode == F_OK) { 147 /* Check file existence by attempt to open it. */ 148 int fd = open(path, O_RDONLY); 149 if (fd < 0) { 150 /* FIXME: open() returns error code as negative retval. */ 151 errno = -fd; 152 fd = -1; 153 } else { 154 close(fd); 155 } 156 return fd; 157 } else if (amode & (X_OK | W_OK | R_OK)) { 158 /* HelenOS doesn't support permissions, return success. */ 159 return 0; 160 } else { 161 /* Invalid amode argument. */ 162 errno = EINVAL; 163 return -1; 164 } 165 } 166 167 /** 168 * Get configurable system variables. 169 * 170 * @param name Variable name. 171 * @return Variable value. 111 172 */ 112 173 long posix_sysconf(int name) 113 174 { 114 // TODO 115 not_implemented(); 175 long clk_tck = 0; 176 size_t cpu_count = 0; 177 stats_cpu_t *cpu_stats = stats_get_cpus(&cpu_count); 178 if (cpu_stats && cpu_count > 0) { 179 clk_tck = ((long) cpu_stats[0].frequency_mhz) * 1000000L; 180 } 181 free(cpu_stats); 182 cpu_stats = 0; 183 184 long phys_pages = 0; 185 long avphys_pages = 0; 186 stats_physmem_t *mem_stats = stats_get_physmem(); 187 if (mem_stats) { 188 phys_pages = (long) (mem_stats->total / getpagesize()); 189 avphys_pages = (long) (mem_stats->free / getpagesize()); 190 } 191 free(mem_stats); 192 mem_stats = 0; 193 194 switch (name) { 195 case _SC_PHYS_PAGES: 196 return phys_pages; 197 case _SC_AVPHYS_PAGES: 198 return avphys_pages; 199 case _SC_PAGESIZE: 200 return getpagesize(); 201 case _SC_CLK_TCK: 202 return clk_tck; 203 default: 204 errno = EINVAL; 205 return -1; 206 } 116 207 } 117 208
Note:
See TracChangeset
for help on using the changeset viewer.