Changes in / [b7ee0369:051e6ac] in mainline
- Location:
- uspace
- Files:
-
- 5 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/assert.h
rb7ee0369 r051e6ac 40 40 41 41 #ifndef NDEBUG 42 #define assert(expr) ((expr) ? (void) 0 : assert_abort(#expr, __FILE__, __LINE__)) 42 #define assert(expr) \ 43 do { \ 44 if (!(expr)) { \ 45 assert_abort(#expr, __FILE__, __LINE__); \ 46 } \ 47 } while (0) 43 48 #else 44 49 #define assert(expr) ((void) 0) -
uspace/lib/posix/ctype.c
rb7ee0369 r051e6ac 94 94 int posix_isprint(int c) 95 95 { 96 return posix_isascii(c) &&!posix_iscntrl(c);96 return !posix_iscntrl(c); 97 97 } 98 98 -
uspace/lib/posix/fnmatch.c
rb7ee0369 r051e6ac 525 525 static char *_casefold(const char *s) 526 526 { 527 assert(s != NULL);528 527 char *result = strdup(s); 529 528 for (char *i = result; *i != '\0'; ++i) { … … 543 542 int posix_fnmatch(const char *pattern, const char *string, int flags) 544 543 { 545 assert(pattern != NULL);546 assert(string != NULL);547 548 544 // TODO: don't fold everything in advance, but only when needed 549 545 -
uspace/lib/posix/internal/common.h
rb7ee0369 r051e6ac 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 55 45 #endif /* LIBPOSIX_COMMON_H_ */ 56 46 -
uspace/lib/posix/pwd.c
rb7ee0369 r051e6ac 39 39 #include "errno.h" 40 40 41 // TODO: documentation 42 41 43 static bool entry_read = false; 42 44 … … 44 46 static const struct posix_passwd dummy_pwd = { 45 47 .pw_name = (char *) "user", 46 .pw_uid = 0,47 .pw_gid = 0,48 .pw_uid = 1, 49 .pw_gid = 1, 48 50 .pw_dir = (char *) "/", 49 51 .pw_shell = (char *) "/app/bdsh" … … 113 115 { 114 116 assert(name != NULL); 115 assert(pwd != NULL);116 assert(buffer != NULL);117 assert(result != NULL);118 117 119 118 if (posix_strcmp(name, "user") != 0) { … … 122 121 } 123 122 124 return posix_getpwuid_r( 0, pwd, buffer, bufsize, result);123 return posix_getpwuid_r(1, pwd, buffer, bufsize, result); 125 124 } 126 125 … … 133 132 struct posix_passwd *posix_getpwuid(posix_uid_t uid) 134 133 { 135 if (uid != 0) {134 if (uid != 1) { 136 135 return NULL; 137 136 } … … 160 159 '/', '\0', 'b', 'd', 's', 'h', '\0' }; 161 160 162 if (uid != 0) {161 if (uid != 1) { 163 162 *result = NULL; 164 163 return 0; … … 172 171 173 172 pwd->pw_name = (char *) bf; 174 pwd->pw_uid = 0;175 pwd->pw_gid = 0;173 pwd->pw_uid = 1; 174 pwd->pw_gid = 1; 176 175 pwd->pw_dir = (char *) bf + 5; 177 176 pwd->pw_shell = (char *) bf + 7; -
uspace/lib/posix/pwd.h
rb7ee0369 r051e6ac 35 35 #ifndef POSIX_PWD_H_ 36 36 #define POSIX_PWD_H_ 37 38 // TODO: documentation 37 39 38 40 #include "sys/types.h" -
uspace/lib/posix/signal.c
rb7ee0369 r051e6ac 66 66 67 67 /** 68 * Default signal handler. Executes the default action for each signal, 69 * as reasonable within HelenOS. 70 * 71 * @param signo Signal number. 68 * 69 * @param signo 72 70 */ 73 71 void __posix_default_signal_handler(int signo) … … 77 75 abort(); 78 76 case SIGQUIT: 79 fprintf(stderr, "Quit signal raised. Exiting. \n");77 fprintf(stderr, "Quit signal raised. Exiting."); 80 78 exit(EXIT_FAILURE); 81 79 case SIGINT: 82 fprintf(stderr, "Interrupt signal caught. Exiting. \n");80 fprintf(stderr, "Interrupt signal caught. Exiting."); 83 81 exit(EXIT_FAILURE); 84 82 case SIGTERM: 85 fprintf(stderr, "Termination signal caught. Exiting. \n");83 fprintf(stderr, "Termination signal caught. Exiting."); 86 84 exit(EXIT_FAILURE); 87 85 case SIGSTOP: 88 fprintf(stderr, "Stop signal caught, but unsupported. Ignoring. \n");86 fprintf(stderr, "Stop signal caught, but unsupported. Ignoring."); 89 87 break; 90 88 case SIGKILL: … … 252 250 " or fully unsupported signal. This handler may only be" 253 251 " invoked by the raise() function, which may not be what" 254 " the application developer intended ");252 " the application developer intended.\nSignal name"); 255 253 } 256 254 … … 360 358 } 361 359 362 if (signo > _TOP_SIGNAL) {363 errno = EINVAL;364 return -1;365 }366 367 360 if (pid == (posix_pid_t) task_get_id()) { 368 361 return posix_raise(signo); 362 } 363 364 if (pid > _TOP_SIGNAL) { 365 errno = EINVAL; 366 return -1; 369 367 } 370 368 -
uspace/lib/posix/stdio.c
rb7ee0369 r051e6ac 44 44 #include "assert.h" 45 45 #include "errno.h" 46 #include "stdlib.h"47 46 #include "string.h" 48 47 #include "sys/types.h" 49 #include "unistd.h"50 48 51 49 #include "libc/io/printf_core.h" 52 50 #include "libc/str.h" 53 51 #include "libc/malloc.h" 54 #include "libc/adt/list.h"55 #include "libc/sys/stat.h"56 52 57 53 … … 256 252 assert(mode != NULL); 257 253 assert(stream != NULL); 254 255 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; 265 return NULL; 266 } 267 268 FILE* copy = malloc(sizeof(FILE)); 269 if (copy == NULL) { 270 errno = ENOMEM; 271 return NULL; 272 } 273 memcpy(copy, stream, sizeof(FILE)); 274 fclose(copy); /* copy is now freed */ 258 275 259 /* Retieve the node. */ 260 struct stat st; 261 int rc; 276 copy = fopen(filename, mode); /* open new stream */ 277 if (copy == NULL) { 278 /* fopen() sets errno */ 279 return NULL; 280 } 262 281 263 if (filename == NULL) { 264 rc = fstat(stream->fd, &st); 265 } else { 266 rc = stat(filename, &st); 267 } 282 /* move the new stream to the original location */ 283 memcpy(stream, copy, sizeof (FILE)); 284 free(copy); 268 285 269 if (rc != EOK) { 270 fclose(stream); 271 errno = -rc; 272 return NULL; 273 } 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. */ 286 return NULL; 287 } 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. */ 286 /* update references in the file list */ 306 287 stream->link.next->prev = &stream->link; 307 288 stream->link.prev->next = &stream->link; … … 695 676 696 677 /** 697 * Remove a file or directory.678 * Remove a file. 698 679 * 699 680 * @param path Pathname of the file that shall be removed. 700 * @return Zero on success, -1 (with errno set)otherwise.681 * @return Zero on success, -1 otherwise. 701 682 */ 702 683 int posix_remove(const char *path) 703 684 { 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. 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 742 694 */ 743 695 char *posix_tmpnam(char *s) 744 696 { 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+"); 697 // TODO: low priority, just a compile-time dependency of binutils 698 not_implemented(); 845 699 } 846 700 -
uspace/lib/posix/stdio.h
rb7ee0369 r051e6ac 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 121 118 /* Temporary Files */ 122 119 #undef L_tmpnam 123 120 #define L_tmpnam PATH_MAX 124 121 extern char *posix_tmpnam(char *s); 125 extern char *posix_tempnam(const char *dir, const char *pfx);126 extern FILE *posix_tmpfile(void);127 122 128 123 #ifndef LIBPOSIX_INTERNAL … … 175 170 #define remove posix_remove 176 171 177 #define rename posix_rename178 179 172 #define tmpnam posix_tmpnam 180 #define tempnam posix_tempnam181 #define tmpfile posix_tmpfile182 173 #endif 183 174 -
uspace/lib/posix/stdlib.c
rb7ee0369 r051e6ac 40 40 41 41 #include "errno.h" 42 #include "fcntl.h"43 42 #include "limits.h" 44 #include "string.h"45 #include "sys/stat.h"46 #include "unistd.h"47 43 48 44 #include "libc/sort.h" … … 389 385 390 386 /** 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. 387 * 388 * @param tmpl 389 * @return 426 390 */ 427 391 char *posix_mktemp(char *tmpl) 428 392 { 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; 393 // TODO: low priority, just a compile-time dependency of binutils 394 not_implemented(); 470 395 } 471 396 -
uspace/lib/posix/stdlib.h
rb7ee0369 r051e6ac 113 113 extern void posix_free(void *ptr); 114 114 115 /* Temporary Files */116 extern int posix_mkstemp(char *tmpl);117 118 115 /* Legacy Declarations */ 119 116 extern char *posix_mktemp(char *tmpl); … … 161 158 #define free posix_free 162 159 163 #define mkstemp posix_mkstemp164 165 160 #define mktemp posix_mktemp 166 161 #define getloadavg bsd_getloadavg -
uspace/lib/posix/sys/wait.c
rb7ee0369 r051e6ac 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; 41 /** 42 * 43 * @param stat_ptr 44 * @return 45 */ 46 posix_pid_t posix_wait(int *stat_ptr) 47 { 48 // TODO: low priority, just a compile-time dependency of binutils 49 not_implemented(); 66 50 } 67 51 68 52 /** 69 * Wait for any child process to stop or terminate.70 53 * 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. 74 */ 75 posix_pid_t posix_wait(int *stat_ptr) 76 { 77 /* HelenOS does not support this. */ 78 errno = ENOSYS; 79 return (posix_pid_t) -1; 80 } 81 82 /** 83 * Wait for a child process to stop or terminate. 84 * 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. 54 * @param pid 55 * @param stat_ptr 56 * @param options 57 * @return 92 58 */ 93 59 posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options) 94 60 { 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; 61 // TODO: low priority, just a compile-time dependency of binutils 62 not_implemented(); 119 63 } 120 64 -
uspace/lib/posix/sys/wait.h
rb7ee0369 r051e6ac 38 38 #include "types.h" 39 39 40 #undef WIFEXITED41 #undef WEXITSTATUS42 #undef WIFSIGNALED43 #undef WTERMSIG44 #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 54 40 extern posix_pid_t posix_wait(int *stat_ptr); 55 41 extern posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options); … … 57 43 #ifndef LIBPOSIX_INTERNAL 58 44 #define wait posix_wait 59 #define waitpid 45 #define waitpid posix_waitpid 60 46 #endif 61 47 -
uspace/lib/posix/unistd.c
rb7ee0369 r051e6ac 110 110 return NULL; 111 111 } 112 113 /* Save the original value to comply with the "no modification on114 * success" semantics.115 */116 int orig_errno = errno;117 errno = EOK;118 119 112 char *ret = getcwd(buf, size); 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 113 if (ret == NULL && errno == EOK) { 114 errno = ERANGE; 115 } 130 116 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);141 117 } 142 118 … … 181 157 /* There is currently no support for user accounts in HelenOS. */ 182 158 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);194 159 } 195 160 … … 204 169 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 205 170 { 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); 171 int rc = read(fildes, buf, nbyte); 172 if (rc < 0) { 173 errno = -rc; 174 return -1; 175 } else { 176 return rc; 177 } 254 178 } 255 179 … … 262 186 int posix_unlink(const char *path) 263 187 { 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); 188 int rc = unlink(path); 189 if (rc < 0) { 190 errno = -rc; 191 return -1; 192 } else { 193 return rc; 194 } 289 195 } 290 196 … … 298 204 int posix_access(const char *path, int amode) 299 205 { 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 */ 206 if (amode == F_OK) { 207 /* Check file existence by attempt to open it. */ 306 208 int fd = open(path, O_RDONLY); 307 if (fd < 0) { 308 errno = -fd; 309 return -1; 209 if (fd != -1) { 210 close(fd); 310 211 } 311 close(fd); 212 return fd; 213 } else if (amode & (X_OK | W_OK | R_OK)) { 214 /* HelenOS doesn't support permissions, return success. */ 312 215 return 0; 313 216 } else { -
uspace/lib/posix/unistd.h
rb7ee0369 r051e6ac 60 60 /* Working Directory */ 61 61 extern char *posix_getcwd(char *buf, size_t size); 62 extern int posix_chdir(const char *path);63 62 64 63 /* Query Memory Parameters */ … … 70 69 extern posix_gid_t posix_getgid(void); 71 70 72 /* File Manipulation */ 73 extern int posix_close(int fildes); 71 /* File Input/Output */ 74 72 extern ssize_t posix_read(int fildes, void *buf, size_t nbyte); 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); 73 74 /* Deleting Files */ 79 75 extern int posix_unlink(const char *path); 80 extern int posix_dup(int fildes);81 extern int posix_dup2(int fildes, int fildes2);82 76 83 77 /* Standard Streams */ … … 150 144 151 145 #define getcwd posix_getcwd 152 #define chdir posix_chdir153 146 154 147 #define isatty posix_isatty … … 161 154 #define getgid posix_getgid 162 155 163 #define close posix_close164 156 #define read posix_read 165 #define write posix_write 166 #define fsync posix_fsync 167 #define ftruncate posix_ftruncate 168 #define rmdir posix_rmdir 157 169 158 #define unlink posix_unlink 170 #define dup posix_dup171 #define dup2 posix_dup2172 159 173 160 #define access posix_access -
uspace/lib/softint/Makefile
rb7ee0369 r051e6ac 35 35 36 36 SOURCES = \ 37 generic/comparison.c \38 37 generic/division.c \ 39 generic/multiplication.c \ 40 generic/shift.c 38 generic/multiplication.c 41 39 42 40 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/hw/irc/apic/apic.c
rb7ee0369 r051e6ac 42 42 #include <as.h> 43 43 #include <ddi.h> 44 #include <libarch/ddi.h> 45 #include <align.h> 44 46 #include <bool.h> 45 47 #include <errno.h> 46 48 #include <async.h> 49 #include <align.h> 50 #include <async.h> 51 #include <stdio.h> 52 #include <ipc/devmap.h> 47 53 48 54 #define NAME "apic" 49 55 50 #define APIC_MAX_IRQ 1551 52 #define IOREGSEL (0x00U / sizeof(uint32_t))53 #define IOWIN (0x10U / sizeof(uint32_t))54 55 #define IOREDTBL 0x10U56 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 kernel92 #define IO_APIC_BASE 0xfec00000UL93 #define IO_APIC_SIZE 2094 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 work133 // for simple cases134 return irq;135 }136 137 56 static int apic_enable_irq(sysarg_t irq) 138 57 { 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; 58 // FIXME: TODO 59 return ENOTSUP; 153 60 } 154 61 … … 204 111 return false; 205 112 } 206 207 if (pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE,208 (void **) &io_apic) != EOK)209 return false;210 113 211 114 async_set_client_connection(apic_connection);
Note:
See TracChangeset
for help on using the changeset viewer.