Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/unistd.c

    rec18957a r823a929  
    3838#include "internal/common.h"
    3939#include "unistd.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"
     40#include <task.h>
    4841
    4942/* Array of environment variable strings (NAME=VALUE). */
    50 char **posix_environ = NULL;
     43char **environ = NULL;
    5144
    5245/**
    53  * Get current user name.
     46 * Dummy function. Always returns false, because there is no easy way to find
     47 * out under HelenOS.
    5448 *
    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.
     49 * @param fd
     50 * @return Always false.
    8751 */
    8852int posix_isatty(int fd)
    8953{
    90         /* Always returns false, because there is no easy way to find
    91      * out under HelenOS. */
    9254        return false;
    9355}
    9456
    9557/**
    96  * Determine the page size of the current run of the process.
    97  *
    98  * @return Page size of the process.
     58 *
     59 * @return
    9960 */
    10061int posix_getpagesize(void)
     
    10465
    10566/**
    106  * Get the process ID of the calling process.
    107  *
    108  * @return Process ID.
     67 *
     68 * @return
    10969 */
    11070posix_pid_t posix_getpid(void)
     
    11474
    11575/**
    116  * Get the real user ID of the calling process.
    11776 *
    118  * @return User ID.
     77 * @return
    11978 */
    12079posix_uid_t posix_getuid(void)
    12180{
    122         /* There is currently no support for user accounts in HelenOS. */
    123         return 0;
     81        // TODO
     82        not_implemented();
    12483}
    12584
    12685/**
    127  * Get the real group ID of the calling process.
    12886 *
    129  * @return Group ID.
     87 * @return
    13088 */
    13189posix_gid_t posix_getgid(void)
    13290{
    133         /* There is currently no support for user accounts in HelenOS. */
    134         return 0;
     91        // TODO
     92        not_implemented();
    13593}
    13694
    13795/**
    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.
     96 *
     97 * @param path
     98 * @param amode
     99 * @return
    143100 */
    144101int posix_access(const char *path, int amode)
    145102{
    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         }
     103        // TODO
     104        not_implemented();
    165105}
    166106
    167107/**
    168  * Get configurable system variables.
    169108 *
    170  * @param name Variable name.
    171  * @return Variable value.
     109 * @param name
     110 * @return
    172111 */
    173112long posix_sysconf(int name)
    174113{
    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         }
     114        // TODO
     115        not_implemented();
    207116}
    208117
Note: See TracChangeset for help on using the changeset viewer.