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