Changes in / [051e6ac:b7ee0369] in mainline
- Location:
- uspace
- Files:
-
- 5 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/assert.h
r051e6ac rb7ee0369 40 40 41 41 #ifndef NDEBUG 42 #define assert(expr) \ 43 do { \ 44 if (!(expr)) { \ 45 assert_abort(#expr, __FILE__, __LINE__); \ 46 } \ 47 } while (0) 42 #define assert(expr) ((expr) ? (void) 0 : assert_abort(#expr, __FILE__, __LINE__)) 48 43 #else 49 44 #define assert(expr) ((void) 0) -
uspace/lib/posix/ctype.c
r051e6ac rb7ee0369 94 94 int posix_isprint(int c) 95 95 { 96 return !posix_iscntrl(c);96 return posix_isascii(c) && !posix_iscntrl(c); 97 97 } 98 98 -
uspace/lib/posix/fnmatch.c
r051e6ac rb7ee0369 525 525 static char *_casefold(const char *s) 526 526 { 527 assert(s != NULL); 527 528 char *result = strdup(s); 528 529 for (char *i = result; *i != '\0'; ++i) { … … 542 543 int posix_fnmatch(const char *pattern, const char *string, int flags) 543 544 { 545 assert(pattern != NULL); 546 assert(string != NULL); 547 544 548 // TODO: don't fold everything in advance, but only when needed 545 549 -
uspace/lib/posix/internal/common.h
r051e6ac rb7ee0369 43 43 __func__, __FILE__, __LINE__), abort()) 44 44 45 /* A little helper macro to avoid typing this over and over. */ 46 #define errnify(func, ...) ({ \ 47 int rc = func(__VA_ARGS__); \ 48 if (rc < 0) { \ 49 errno = -rc; \ 50 rc = -1; \ 51 } \ 52 rc; \ 53 }) 54 45 55 #endif /* LIBPOSIX_COMMON_H_ */ 46 56 -
uspace/lib/posix/pwd.c
r051e6ac rb7ee0369 39 39 #include "errno.h" 40 40 41 // TODO: documentation42 43 41 static bool entry_read = false; 44 42 … … 46 44 static const struct posix_passwd dummy_pwd = { 47 45 .pw_name = (char *) "user", 48 .pw_uid = 1,49 .pw_gid = 1,46 .pw_uid = 0, 47 .pw_gid = 0, 50 48 .pw_dir = (char *) "/", 51 49 .pw_shell = (char *) "/app/bdsh" … … 115 113 { 116 114 assert(name != NULL); 115 assert(pwd != NULL); 116 assert(buffer != NULL); 117 assert(result != NULL); 117 118 118 119 if (posix_strcmp(name, "user") != 0) { … … 121 122 } 122 123 123 return posix_getpwuid_r( 1, pwd, buffer, bufsize, result);124 return posix_getpwuid_r(0, pwd, buffer, bufsize, result); 124 125 } 125 126 … … 132 133 struct posix_passwd *posix_getpwuid(posix_uid_t uid) 133 134 { 134 if (uid != 1) {135 if (uid != 0) { 135 136 return NULL; 136 137 } … … 159 160 '/', '\0', 'b', 'd', 's', 'h', '\0' }; 160 161 161 if (uid != 1) {162 if (uid != 0) { 162 163 *result = NULL; 163 164 return 0; … … 171 172 172 173 pwd->pw_name = (char *) bf; 173 pwd->pw_uid = 1;174 pwd->pw_gid = 1;174 pwd->pw_uid = 0; 175 pwd->pw_gid = 0; 175 176 pwd->pw_dir = (char *) bf + 5; 176 177 pwd->pw_shell = (char *) bf + 7; -
uspace/lib/posix/pwd.h
r051e6ac rb7ee0369 35 35 #ifndef POSIX_PWD_H_ 36 36 #define POSIX_PWD_H_ 37 38 // TODO: documentation39 37 40 38 #include "sys/types.h" -
uspace/lib/posix/signal.c
r051e6ac rb7ee0369 66 66 67 67 /** 68 * 69 * @param signo 68 * Default signal handler. Executes the default action for each signal, 69 * as reasonable within HelenOS. 70 * 71 * @param signo Signal number. 70 72 */ 71 73 void __posix_default_signal_handler(int signo) … … 75 77 abort(); 76 78 case SIGQUIT: 77 fprintf(stderr, "Quit signal raised. Exiting. ");79 fprintf(stderr, "Quit signal raised. Exiting.\n"); 78 80 exit(EXIT_FAILURE); 79 81 case SIGINT: 80 fprintf(stderr, "Interrupt signal caught. Exiting. ");82 fprintf(stderr, "Interrupt signal caught. Exiting.\n"); 81 83 exit(EXIT_FAILURE); 82 84 case SIGTERM: 83 fprintf(stderr, "Termination signal caught. Exiting. ");85 fprintf(stderr, "Termination signal caught. Exiting.\n"); 84 86 exit(EXIT_FAILURE); 85 87 case SIGSTOP: 86 fprintf(stderr, "Stop signal caught, but unsupported. Ignoring. ");88 fprintf(stderr, "Stop signal caught, but unsupported. Ignoring.\n"); 87 89 break; 88 90 case SIGKILL: … … 250 252 " or fully unsupported signal. This handler may only be" 251 253 " invoked by the raise() function, which may not be what" 252 " the application developer intended .\nSignal name");254 " the application developer intended"); 253 255 } 254 256 … … 358 360 } 359 361 362 if (signo > _TOP_SIGNAL) { 363 errno = EINVAL; 364 return -1; 365 } 366 360 367 if (pid == (posix_pid_t) task_get_id()) { 361 368 return posix_raise(signo); 362 }363 364 if (pid > _TOP_SIGNAL) {365 errno = EINVAL;366 return -1;367 369 } 368 370 -
uspace/lib/posix/stdio.c
r051e6ac rb7ee0369 44 44 #include "assert.h" 45 45 #include "errno.h" 46 #include "stdlib.h" 46 47 #include "string.h" 47 48 #include "sys/types.h" 49 #include "unistd.h" 48 50 49 51 #include "libc/io/printf_core.h" 50 52 #include "libc/str.h" 51 53 #include "libc/malloc.h" 54 #include "libc/adt/list.h" 55 #include "libc/sys/stat.h" 52 56 53 57 … … 252 256 assert(mode != NULL); 253 257 assert(stream != NULL); 254 258 259 /* Retieve the node. */ 260 struct stat st; 261 int rc; 262 255 263 if (filename == NULL) { 256 // TODO 257 258 /* print error to stderr as well, to avoid hard to find problems 259 * with buggy apps that expect this to work 260 */ 261 fprintf(stderr, 262 "ERROR: Application wants to use freopen() to change mode of opened stream.\n" 263 " libposix does not support that yet, the application may function improperly.\n"); 264 errno = ENOTSUP; 264 rc = fstat(stream->fd, &st); 265 } else { 266 rc = stat(filename, &st); 267 } 268 269 if (rc != EOK) { 270 fclose(stream); 271 errno = -rc; 265 272 return NULL; 266 273 } 267 268 FILE* copy = malloc(sizeof(FILE)); 269 if (copy == NULL) { 270 errno = ENOMEM; 274 275 fdi_node_t node = { 276 .fs_handle = st.fs_handle, 277 .devmap_handle = st.devmap_handle, 278 .index = st.index 279 }; 280 281 /* Open a new stream. */ 282 FILE* new = fopen_node(&node, mode); 283 if (new == NULL) { 284 fclose(stream); 285 /* fopen_node() sets errno. */ 271 286 return NULL; 272 287 } 273 memcpy(copy, stream, sizeof(FILE)); 274 fclose(copy); /* copy is now freed */ 275 276 copy = fopen(filename, mode); /* open new stream */ 277 if (copy == NULL) { 278 /* fopen() sets errno */ 279 return NULL; 280 } 281 282 /* move the new stream to the original location */ 283 memcpy(stream, copy, sizeof (FILE)); 284 free(copy); 285 286 /* update references in the file list */ 288 289 /* Close the original stream without freeing it (ignoring errors). */ 290 if (stream->buf != NULL) { 291 fflush(stream); 292 } 293 if (stream->sess != NULL) { 294 async_hangup(stream->sess); 295 } 296 if (stream->fd >= 0) { 297 close(stream->fd); 298 } 299 list_remove(&stream->link); 300 301 /* Move the new stream to the original location. */ 302 memcpy(stream, new, sizeof (FILE)); 303 free(new); 304 305 /* Update references in the file list. */ 287 306 stream->link.next->prev = &stream->link; 288 307 stream->link.prev->next = &stream->link; … … 676 695 677 696 /** 678 * Remove a file .697 * Remove a file or directory. 679 698 * 680 699 * @param path Pathname of the file that shall be removed. 681 * @return Zero on success, -1 otherwise.700 * @return Zero on success, -1 (with errno set) otherwise. 682 701 */ 683 702 int posix_remove(const char *path) 684 703 { 685 // FIXME: unlink() and rmdir() seem to be equivalent at the moment, 686 // but that does not have to be true forever 687 return unlink(path); 688 } 689 690 /** 691 * 692 * @param s 693 * @return 704 struct stat st; 705 int rc = stat(path, &st); 706 707 if (rc != EOK) { 708 errno = -rc; 709 return -1; 710 } 711 712 if (st.is_directory) { 713 rc = rmdir(path); 714 } else { 715 rc = unlink(path); 716 } 717 718 if (rc != EOK) { 719 errno = -rc; 720 return -1; 721 } 722 return 0; 723 } 724 725 /** 726 * Rename a file or directory. 727 * 728 * @param old Old pathname. 729 * @param new New pathname. 730 * @return Zero on success, -1 (with errno set) otherwise. 731 */ 732 int posix_rename(const char *old, const char *new) 733 { 734 return errnify(rename, old, new); 735 } 736 737 /** 738 * Get a unique temporary file name (obsolete). 739 * 740 * @param s Buffer for the file name. Must be at least L_tmpnam bytes long. 741 * @return The value of s on success, NULL on failure. 694 742 */ 695 743 char *posix_tmpnam(char *s) 696 744 { 697 // TODO: low priority, just a compile-time dependency of binutils 698 not_implemented(); 745 assert(L_tmpnam >= posix_strlen("/tmp/tnXXXXXX")); 746 747 static char buffer[L_tmpnam + 1]; 748 if (s == NULL) { 749 s = buffer; 750 } 751 752 posix_strcpy(s, "/tmp/tnXXXXXX"); 753 posix_mktemp(s); 754 755 if (*s == '\0') { 756 /* Errno set by mktemp(). */ 757 return NULL; 758 } 759 760 return s; 761 } 762 763 /** 764 * Get an unique temporary file name with additional constraints (obsolete). 765 * 766 * @param dir Path to directory, where the file should be created. 767 * @param pfx Optional prefix up to 5 characters long. 768 * @return Newly allocated unique path for temporary file. NULL on failure. 769 */ 770 char *posix_tempnam(const char *dir, const char *pfx) 771 { 772 /* Sequence number of the filename. */ 773 static int seq = 0; 774 775 size_t dir_len = posix_strlen(dir); 776 if (dir[dir_len - 1] == '/') { 777 dir_len--; 778 } 779 780 size_t pfx_len = posix_strlen(pfx); 781 if (pfx_len > 5) { 782 pfx_len = 5; 783 } 784 785 char *result = malloc(dir_len + /* slash*/ 1 + 786 pfx_len + /* three-digit seq */ 3 + /* .tmp */ 4 + /* nul */ 1); 787 788 if (result == NULL) { 789 errno = ENOMEM; 790 return NULL; 791 } 792 793 char *res_ptr = result; 794 posix_strncpy(res_ptr, dir, dir_len); 795 res_ptr += dir_len; 796 posix_strncpy(res_ptr, pfx, pfx_len); 797 res_ptr += pfx_len; 798 799 for (; seq < 1000; ++seq) { 800 snprintf(res_ptr, 8, "%03d.tmp", seq); 801 802 int orig_errno = errno; 803 errno = 0; 804 /* Check if the file exists. */ 805 if (posix_access(result, F_OK) == -1) { 806 if (errno == ENOENT) { 807 errno = orig_errno; 808 break; 809 } else { 810 /* errno set by access() */ 811 return NULL; 812 } 813 } 814 } 815 816 if (seq == 1000) { 817 free(result); 818 errno = EINVAL; 819 return NULL; 820 } 821 822 return result; 823 } 824 825 /** 826 * Create and open an unique temporary file. 827 * The file is automatically removed when the stream is closed. 828 * 829 * @param dir Path to directory, where the file should be created. 830 * @param pfx Optional prefix up to 5 characters long. 831 * @return Newly allocated unique path for temporary file. NULL on failure. 832 */ 833 FILE *posix_tmpfile(void) 834 { 835 char filename[] = "/tmp/tfXXXXXX"; 836 int fd = posix_mkstemp(filename); 837 if (fd == -1) { 838 /* errno set by mkstemp(). */ 839 return NULL; 840 } 841 842 /* Unlink the created file, so that it's removed on close(). */ 843 posix_unlink(filename); 844 return fdopen(fd, "w+"); 699 845 } 700 846 -
uspace/lib/posix/stdio.h
r051e6ac rb7ee0369 116 116 extern int posix_remove(const char *path); 117 117 118 /* Renaming Files */ 119 extern int posix_rename(const char *old, const char *new); 120 118 121 /* Temporary Files */ 119 122 #undef L_tmpnam 120 123 #define L_tmpnam PATH_MAX 121 124 extern char *posix_tmpnam(char *s); 125 extern char *posix_tempnam(const char *dir, const char *pfx); 126 extern FILE *posix_tmpfile(void); 122 127 123 128 #ifndef LIBPOSIX_INTERNAL … … 170 175 #define remove posix_remove 171 176 177 #define rename posix_rename 178 172 179 #define tmpnam posix_tmpnam 180 #define tempnam posix_tempnam 181 #define tmpfile posix_tmpfile 173 182 #endif 174 183 -
uspace/lib/posix/stdlib.c
r051e6ac rb7ee0369 40 40 41 41 #include "errno.h" 42 #include "fcntl.h" 42 43 #include "limits.h" 44 #include "string.h" 45 #include "sys/stat.h" 46 #include "unistd.h" 43 47 44 48 #include "libc/sort.h" … … 385 389 386 390 /** 387 * 388 * @param tmpl 389 * @return 391 * Creates and opens an unique temporary file from template. 392 * 393 * @param tmpl Template. Last six characters must be XXXXXX. 394 * @return The opened file descriptor or -1 on error. 395 */ 396 int posix_mkstemp(char *tmpl) 397 { 398 int fd = -1; 399 400 char *tptr = tmpl + posix_strlen(tmpl) - 6; 401 402 while (fd < 0) { 403 if (*posix_mktemp(tmpl) == '\0') { 404 /* Errno set by mktemp(). */ 405 return -1; 406 } 407 408 fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); 409 410 if (fd == -1) { 411 /* Restore template to it's original state. */ 412 snprintf(tptr, 7, "XXXXXX"); 413 } 414 } 415 416 return fd; 417 } 418 419 /** 420 * Creates an unique temporary file name from template. 421 * 422 * @param tmpl Template. Last six characters must be XXXXXX. 423 * @return The value of tmpl. The template is modified in place. 424 * If no temporary file name can be created, template is 425 * reduced to an empty string. 390 426 */ 391 427 char *posix_mktemp(char *tmpl) 392 428 { 393 // TODO: low priority, just a compile-time dependency of binutils 394 not_implemented(); 429 int tmpl_len = posix_strlen(tmpl); 430 if (tmpl_len < 6) { 431 errno = EINVAL; 432 *tmpl = '\0'; 433 return tmpl; 434 } 435 436 char *tptr = tmpl + tmpl_len - 6; 437 if (posix_strcmp(tptr, "XXXXXX") != 0) { 438 errno = EINVAL; 439 *tmpl = '\0'; 440 return tmpl; 441 } 442 443 static int seq = 0; 444 445 for (; seq < 1000000; ++seq) { 446 snprintf(tptr, 7, "%06d", seq); 447 448 int orig_errno = errno; 449 errno = 0; 450 /* Check if the file exists. */ 451 if (posix_access(tmpl, F_OK) == -1) { 452 if (errno == ENOENT) { 453 errno = orig_errno; 454 break; 455 } else { 456 /* errno set by access() */ 457 *tmpl = '\0'; 458 return tmpl; 459 } 460 } 461 } 462 463 if (seq == 10000000) { 464 errno = EEXIST; 465 *tmpl = '\0'; 466 return tmpl; 467 } 468 469 return tmpl; 395 470 } 396 471 -
uspace/lib/posix/stdlib.h
r051e6ac rb7ee0369 113 113 extern void posix_free(void *ptr); 114 114 115 /* Temporary Files */ 116 extern int posix_mkstemp(char *tmpl); 117 115 118 /* Legacy Declarations */ 116 119 extern char *posix_mktemp(char *tmpl); … … 158 161 #define free posix_free 159 162 163 #define mkstemp posix_mkstemp 164 160 165 #define mktemp posix_mktemp 161 166 #define getloadavg bsd_getloadavg -
uspace/lib/posix/sys/wait.c
r051e6ac rb7ee0369 39 39 #include "wait.h" 40 40 41 #include "../libc/task.h" 42 #include "../assert.h" 43 #include "../errno.h" 44 #include "../limits.h" 45 #include "../signal.h" 46 47 int __posix_wifexited(int status) { 48 return status != INT_MIN; 49 } 50 51 int __posix_wexitstatus(int status) { 52 assert(__posix_wifexited(status)); 53 return status; 54 } 55 56 int __posix_wifsignaled(int status) { 57 return status == INT_MIN; 58 } 59 60 int __posix_wtermsig(int status) { 61 assert(__posix_wifsignaled(status)); 62 /* There is no way to distinguish reason 63 * for unexpected termination at the moment. 64 */ 65 return SIGABRT; 66 } 67 41 68 /** 69 * Wait for any child process to stop or terminate. 42 70 * 43 * @param stat_ptr 44 * @return 71 * @param stat_ptr Location of the final status code of the child process. 72 * @return ID of the child process for which status is reported, 73 * -1 on signal interrupt, (pid_t)-1 otherwise. 45 74 */ 46 75 posix_pid_t posix_wait(int *stat_ptr) 47 76 { 48 // TODO: low priority, just a compile-time dependency of binutils 49 not_implemented(); 77 /* HelenOS does not support this. */ 78 errno = ENOSYS; 79 return (posix_pid_t) -1; 50 80 } 51 81 52 82 /** 83 * Wait for a child process to stop or terminate. 53 84 * 54 * @param pid 55 * @param stat_ptr 56 * @param options 57 * @return 85 * @param pid What child process shall the caller wait for. See POSIX manual 86 * for details. 87 * @param stat_ptr Location of the final status code of the child process. 88 * @param options Constraints of the waiting. See POSIX manual for details. 89 * @return ID of the child process for which status is reported, 90 * -1 on signal interrupt, 0 if non-blocking wait is requested but there is 91 * no child process whose status can be reported, (pid_t)-1 otherwise. 58 92 */ 59 93 posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options) 60 94 { 61 // TODO: low priority, just a compile-time dependency of binutils 62 not_implemented(); 95 assert(stat_ptr != NULL); 96 assert(options == 0 /* None of the options are supported. */); 97 98 task_exit_t texit; 99 int retval; 100 101 int rc = task_wait((task_id_t) pid, &texit, &retval); 102 103 if (rc < 0) { 104 /* Unable to retrieve status. */ 105 errno = -rc; 106 return (posix_pid_t) -1; 107 } 108 109 if (texit == TASK_EXIT_NORMAL) { 110 // FIXME: relies on application not returning this value 111 assert(retval != INT_MIN); 112 *stat_ptr = retval; 113 } else { 114 /* Reserve the lowest value for unexpected termination. */ 115 *stat_ptr = INT_MIN; 116 } 117 118 return pid; 63 119 } 64 120 -
uspace/lib/posix/sys/wait.h
r051e6ac rb7ee0369 38 38 #include "types.h" 39 39 40 #undef WIFEXITED 41 #undef WEXITSTATUS 42 #undef WIFSIGNALED 43 #undef WTERMSIG 44 #define WIFEXITED(status) __posix_wifexited(status) 45 #define WEXITSTATUS(status) __posix_wexitstatus(status) 46 #define WIFSIGNALED(status) __posix_wifsignaled(status) 47 #define WTERMSIG(status) __posix_wtermsig(status) 48 49 extern int __posix_wifexited(int status); 50 extern int __posix_wexitstatus(int status); 51 extern int __posix_wifsignaled(int status); 52 extern int __posix_wtermsig(int status); 53 40 54 extern posix_pid_t posix_wait(int *stat_ptr); 41 55 extern posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options); … … 43 57 #ifndef LIBPOSIX_INTERNAL 44 58 #define wait posix_wait 45 #define waitpid 59 #define waitpid posix_waitpid 46 60 #endif 47 61 -
uspace/lib/posix/unistd.c
r051e6ac rb7ee0369 110 110 return NULL; 111 111 } 112 113 /* Save the original value to comply with the "no modification on 114 * success" semantics. 115 */ 116 int orig_errno = errno; 117 errno = EOK; 118 112 119 char *ret = getcwd(buf, size); 113 if (ret == NULL && errno == EOK) { 114 errno = ERANGE; 115 } 120 if (ret == NULL) { 121 /* Check errno to avoid shadowing other possible errors. */ 122 if (errno == EOK) { 123 errno = ERANGE; 124 } 125 } else { 126 /* Success, restore previous errno value. */ 127 errno = orig_errno; 128 } 129 116 130 return ret; 131 } 132 133 /** 134 * Change the current working directory. 135 * 136 * @param path New working directory. 137 */ 138 int posix_chdir(const char *path) 139 { 140 return errnify(chdir, path); 117 141 } 118 142 … … 157 181 /* There is currently no support for user accounts in HelenOS. */ 158 182 return 0; 183 } 184 185 /** 186 * Close a file. 187 * 188 * @param fildes File descriptor of the opened file. 189 * @return 0 on success, -1 on error. 190 */ 191 int posix_close(int fildes) 192 { 193 return errnify(close, fildes); 159 194 } 160 195 … … 169 204 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 170 205 { 171 int rc = read(fildes, buf, nbyte); 172 if (rc < 0) { 173 errno = -rc; 174 return -1; 175 } else { 176 return rc; 177 } 206 return errnify(read, fildes, buf, nbyte); 207 } 208 209 /** 210 * Write to a file. 211 * 212 * @param fildes File descriptor of the opened file. 213 * @param buf Buffer to write. 214 * @param nbyte Size of the buffer. 215 * @return Number of written bytes on success, -1 otherwise. 216 */ 217 ssize_t posix_write(int fildes, const void *buf, size_t nbyte) 218 { 219 return errnify(write, fildes, buf, nbyte); 220 } 221 222 /** 223 * Requests outstanding data to be written to the underlying storage device. 224 * 225 * @param fildes File descriptor of the opened file. 226 * @return Zero on success, -1 otherwise. 227 */ 228 int posix_fsync(int fildes) 229 { 230 return errnify(fsync, fildes); 231 } 232 233 /** 234 * Truncate a file to a specified length. 235 * 236 * @param fildes File descriptor of the opened file. 237 * @param length New length of the file. 238 * @return Zero on success, -1 otherwise. 239 */ 240 int posix_ftruncate(int fildes, posix_off_t length) 241 { 242 return errnify(ftruncate, fildes, (aoff64_t) length); 243 } 244 245 /** 246 * Remove a directory. 247 * 248 * @param path Directory pathname. 249 * @return Zero on success, -1 otherwise. 250 */ 251 int posix_rmdir(const char *path) 252 { 253 return errnify(rmdir, path); 178 254 } 179 255 … … 186 262 int posix_unlink(const char *path) 187 263 { 188 int rc = unlink(path); 189 if (rc < 0) { 190 errno = -rc; 191 return -1; 192 } else { 193 return rc; 194 } 264 return errnify(unlink, path); 265 } 266 267 /** 268 * Duplicate an open file descriptor. 269 * 270 * @param fildes File descriptor to be duplicated. 271 * @return On success, new file descriptor for the same file, otherwise -1. 272 */ 273 int posix_dup(int fildes) 274 { 275 return posix_fcntl(fildes, F_DUPFD, 0); 276 } 277 278 /** 279 * Duplicate an open file descriptor. 280 * 281 * @param fildes File descriptor to be duplicated. 282 * @param fildes2 File descriptor to be paired with the same file description 283 * as is paired fildes. 284 * @return fildes2 on success, -1 otherwise. 285 */ 286 int posix_dup2(int fildes, int fildes2) 287 { 288 return errnify(dup2, fildes, fildes2); 195 289 } 196 290 … … 204 298 int posix_access(const char *path, int amode) 205 299 { 206 if (amode == F_OK) { 207 /* Check file existence by attempt to open it. */ 300 if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) { 301 /* HelenOS doesn't support permissions, permission checks 302 * are equal to existence check. 303 * 304 * Check file existence by attempting to open it. 305 */ 208 306 int fd = open(path, O_RDONLY); 209 if (fd != -1) { 210 close(fd); 307 if (fd < 0) { 308 errno = -fd; 309 return -1; 211 310 } 212 return fd; 213 } else if (amode & (X_OK | W_OK | R_OK)) { 214 /* HelenOS doesn't support permissions, return success. */ 311 close(fd); 215 312 return 0; 216 313 } else { -
uspace/lib/posix/unistd.h
r051e6ac rb7ee0369 60 60 /* Working Directory */ 61 61 extern char *posix_getcwd(char *buf, size_t size); 62 extern int posix_chdir(const char *path); 62 63 63 64 /* Query Memory Parameters */ … … 69 70 extern posix_gid_t posix_getgid(void); 70 71 71 /* File Input/Output */ 72 /* File Manipulation */ 73 extern int posix_close(int fildes); 72 74 extern ssize_t posix_read(int fildes, void *buf, size_t nbyte); 73 74 /* Deleting Files */ 75 extern ssize_t posix_write(int fildes, const void *buf, size_t nbyte); 76 extern int posix_fsync(int fildes); 77 extern int posix_ftruncate(int fildes, posix_off_t length); 78 extern int posix_rmdir(const char *path); 75 79 extern int posix_unlink(const char *path); 80 extern int posix_dup(int fildes); 81 extern int posix_dup2(int fildes, int fildes2); 76 82 77 83 /* Standard Streams */ … … 144 150 145 151 #define getcwd posix_getcwd 152 #define chdir posix_chdir 146 153 147 154 #define isatty posix_isatty … … 154 161 #define getgid posix_getgid 155 162 163 #define close posix_close 156 164 #define read posix_read 157 165 #define write posix_write 166 #define fsync posix_fsync 167 #define ftruncate posix_ftruncate 168 #define rmdir posix_rmdir 158 169 #define unlink posix_unlink 170 #define dup posix_dup 171 #define dup2 posix_dup2 159 172 160 173 #define access posix_access -
uspace/lib/softint/Makefile
r051e6ac rb7ee0369 35 35 36 36 SOURCES = \ 37 generic/comparison.c \ 37 38 generic/division.c \ 38 generic/multiplication.c 39 generic/multiplication.c \ 40 generic/shift.c 39 41 40 42 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/hw/irc/apic/apic.c
r051e6ac rb7ee0369 42 42 #include <as.h> 43 43 #include <ddi.h> 44 #include <libarch/ddi.h>45 #include <align.h>46 44 #include <bool.h> 47 45 #include <errno.h> 48 46 #include <async.h> 49 #include <align.h>50 #include <async.h>51 #include <stdio.h>52 #include <ipc/devmap.h>53 47 54 48 #define NAME "apic" 55 49 50 #define APIC_MAX_IRQ 15 51 52 #define IOREGSEL (0x00U / sizeof(uint32_t)) 53 #define IOWIN (0x10U / sizeof(uint32_t)) 54 55 #define IOREDTBL 0x10U 56 57 /** I/O Register Select Register. */ 58 typedef union { 59 uint32_t value; 60 struct { 61 uint8_t reg_addr; /**< APIC Register Address. */ 62 unsigned int : 24; /**< Reserved. */ 63 } __attribute__ ((packed)); 64 } io_regsel_t; 65 66 /** I/O Redirection Register. */ 67 typedef struct io_redirection_reg { 68 union { 69 uint32_t lo; 70 struct { 71 uint8_t intvec; /**< Interrupt Vector. */ 72 unsigned int delmod : 3; /**< Delivery Mode. */ 73 unsigned int destmod : 1; /**< Destination mode. */ 74 unsigned int delivs : 1; /**< Delivery status (RO). */ 75 unsigned int intpol : 1; /**< Interrupt Input Pin Polarity. */ 76 unsigned int irr : 1; /**< Remote IRR (RO). */ 77 unsigned int trigger_mode : 1; /**< Trigger Mode. */ 78 unsigned int masked : 1; /**< Interrupt Mask. */ 79 unsigned int : 15; /**< Reserved. */ 80 } __attribute__ ((packed)); 81 }; 82 union { 83 uint32_t hi; 84 struct { 85 unsigned int : 24; /**< Reserved. */ 86 uint8_t dest : 8; /**< Destination Field. */ 87 } __attribute__ ((packed)); 88 }; 89 } __attribute__ ((packed)) io_redirection_reg_t; 90 91 // FIXME: get the address from the kernel 92 #define IO_APIC_BASE 0xfec00000UL 93 #define IO_APIC_SIZE 20 94 95 ioport32_t *io_apic = NULL; 96 97 /** Read from IO APIC register. 98 * 99 * @param address IO APIC register address. 100 * 101 * @return Content of the addressed IO APIC register. 102 * 103 */ 104 static uint32_t io_apic_read(uint8_t address) 105 { 106 io_regsel_t regsel; 107 108 regsel.value = io_apic[IOREGSEL]; 109 regsel.reg_addr = address; 110 io_apic[IOREGSEL] = regsel.value; 111 return io_apic[IOWIN]; 112 } 113 114 /** Write to IO APIC register. 115 * 116 * @param address IO APIC register address. 117 * @param val Content to be written to the addressed IO APIC register. 118 * 119 */ 120 static void io_apic_write(uint8_t address, uint32_t val) 121 { 122 io_regsel_t regsel; 123 124 regsel.value = io_apic[IOREGSEL]; 125 regsel.reg_addr = address; 126 io_apic[IOREGSEL] = regsel.value; 127 io_apic[IOWIN] = val; 128 } 129 130 static int irq_to_pin(int irq) 131 { 132 // FIXME: get the map from the kernel, even though this may work 133 // for simple cases 134 return irq; 135 } 136 56 137 static int apic_enable_irq(sysarg_t irq) 57 138 { 58 // FIXME: TODO 59 return ENOTSUP; 139 io_redirection_reg_t reg; 140 141 if (irq > APIC_MAX_IRQ) 142 return ELIMIT; 143 144 int pin = irq_to_pin(irq); 145 if (pin == -1) 146 return ENOENT; 147 148 reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2)); 149 reg.masked = false; 150 io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo); 151 152 return EOK; 60 153 } 61 154 … … 111 204 return false; 112 205 } 206 207 if (pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE, 208 (void **) &io_apic) != EOK) 209 return false; 113 210 114 211 async_set_client_connection(apic_connection);
Note:
See TracChangeset
for help on using the changeset viewer.