Changeset d96d9bc in mainline


Ignore:
Timestamp:
2017-04-02T20:38:50Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c23275a
Parents:
1e2e5795
Message:

Rename chdir() to vfs_cwd_set() and getcwd() to vfs_cwd_get()

Location:
uspace
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/builtins/cd/cd.c

    r1e2e5795 rd96d9bc  
    2929#include <stdio.h>
    3030#include <stdlib.h>
    31 #include <unistd.h>
    3231#include <str.h>
    3332#include <errno.h>
     33#include <vfs/vfs.h>
    3434
    3535#include "util.h"
     
    5151static bool previous_directory_set = false;
    5252
    53 static int chdir_and_remember(const char *new_dir) {
     53static int chdir_and_remember(const char *new_dir)
     54{
    5455
    55         char *ok = getcwd(previous_directory_tmp, PATH_MAX);
    56         previous_directory_valid = ok != NULL;
     56        int rc = vfs_cwd_get(previous_directory_tmp, PATH_MAX);
     57        previous_directory_valid = (rc == EOK);
    5758        previous_directory_set = true;
    5859
    59         if (chdir(new_dir) != 0)
    60                 return errno;
     60        rc = vfs_cwd_set(new_dir);
     61        if (rc != EOK)
     62                return rc;
    6163
    6264        str_cpy(previous_directory, PATH_MAX, previous_directory_tmp);
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r1e2e5795 rd96d9bc  
    3434#include <stdio.h>
    3535#include <stdlib.h>
    36 #include <unistd.h>
    3736#include <dirent.h>
    3837#include <getopt.h>
     
    387386
    388387        if (argc == 0) {
    389                 if (getcwd(de.name, PATH_MAX) == NULL) {
     388                if (vfs_cwd_get(de.name, PATH_MAX) != EOK) {
    390389                        cli_error(CL_EFAIL, "%s: Failed determining working "
    391390                            "directory", cmdname);
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    r1e2e5795 rd96d9bc  
    208208
    209209        if (follow && (argv[optind] != NULL)) {
    210                 if (chdir(argv[optind]) != 0)
     210                if (vfs_cwd_set(argv[optind]) != EOK)
    211211                        printf("%s: Error switching to directory.", cmdname);
    212212        }
  • uspace/app/bdsh/cmds/modules/pwd/pwd.c

    r1e2e5795 rd96d9bc  
    3030#include <stdlib.h>
    3131#include <mem.h>
     32#include <vfs/vfs.h>
     33#include <abi/errno.h>
    3234
    3335#include "config.h"
     
    5759        memset(buff, 0, PATH_MAX);
    5860
    59         if (getcwd(buff, PATH_MAX) == NULL) {
     61        if (vfs_cwd_get(buff, PATH_MAX) != EOK) {
    6062                cli_error(CL_EFAIL,
    6163                        "Unable to determine the current working directory");
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    r1e2e5795 rd96d9bc  
    3030#include <stdio.h>
    3131#include <stdlib.h>
    32 #include <unistd.h>
    3332#include <dirent.h>
    3433#include <getopt.h>
     
    110109        memset(rm->cwd, 0, PATH_MAX);
    111110
    112         chdir(".");
    113 
    114         if (NULL == (getcwd(rm->owd, PATH_MAX)))
     111        vfs_cwd_set(".");
     112
     113        if (EOK != vfs_cwd_get(rm->owd, PATH_MAX))
    115114                return 0;
    116115
  • uspace/app/bdsh/util.c

    r1e2e5795 rd96d9bc  
    3131#include <stdarg.h>
    3232#include <stdlib.h>
     33#include <vfs/vfs.h>
     34#include <abi/errno.h>
    3335
    3436#include "config.h"
     
    5860                return 1;
    5961        }
    60         if (!getcwd(usr->cwd, PATH_MAX))
     62        if (vfs_cwd_get(usr->cwd, PATH_MAX) != EOK)
    6163                snprintf(usr->cwd, PATH_MAX, "(unknown)");
    6264
  • uspace/lib/c/generic/libc.c

    r1e2e5795 rd96d9bc  
    116116                __stdio_init();
    117117                vfs_root_set(inbox_get("root"));
    118                 (void) chdir(__pcb->cwd);
     118                (void) vfs_cwd_set(__pcb->cwd);
    119119        }
    120120       
  • uspace/lib/c/generic/loader.c

    r1e2e5795 rd96d9bc  
    124124                return ENOMEM;
    125125       
    126         if (getcwd(cwd, MAX_PATH_LEN + 1) == NULL)
     126        if (vfs_cwd_get(cwd, MAX_PATH_LEN + 1) != EOK)
    127127                str_cpy(cwd, MAX_PATH_LEN + 1, "/");
    128128       
  • uspace/lib/c/generic/vfs/vfs.c

    r1e2e5795 rd96d9bc  
    808808 *
    809809 * @param path Path
    810  * @return 0 on success. On error returns -1 and sets errno.
    811  */
    812 int chdir(const char *path)
     810 * @return EOK on success or a negative error code otherwise.
     811 */
     812int vfs_cwd_set(const char *path)
    813813{
    814814        size_t abs_size;
    815815        char *abs = vfs_absolutize(path, &abs_size);
    816         if (!abs) {
    817                 errno = ENOMEM;
    818                 return -1;
    819         }
     816        if (!abs)
     817                return ENOMEM;
    820818       
    821819        int fd = vfs_lookup(abs, WALK_DIRECTORY);
    822820        if (fd < 0) {
    823821                free(abs);
    824                 errno = fd;
    825                 return -1;
     822                return fd;
    826823        }
    827824       
     
    839836       
    840837        fibril_mutex_unlock(&cwd_mutex);
    841         return 0;
     838        return EOK;
    842839}
    843840
     
    846843 * @param buf Buffer
    847844 * @param size Size of @a buf
    848  * @return On success returns @a buf. On failure returns @c NULL and sets errno.
    849  */
    850 char *getcwd(char *buf, size_t size)
    851 {
    852         if (size == 0) {
    853                 errno = EINVAL;
    854                 return NULL;
    855         }
    856        
     845 * @return EOK on success and a non-negative error code otherwise.
     846 */
     847int vfs_cwd_get(char *buf, size_t size)
     848{
    857849        fibril_mutex_lock(&cwd_mutex);
    858850       
    859851        if ((cwd_size == 0) || (size < cwd_size + 1)) {
    860852                fibril_mutex_unlock(&cwd_mutex);
    861                 errno = ERANGE;
    862                 return NULL;
     853                return ERANGE;
    863854        }
    864855       
     
    866857        fibril_mutex_unlock(&cwd_mutex);
    867858       
    868         return buf;
     859        return EOK;
    869860}
    870861
  • uspace/lib/c/include/unistd.h

    r1e2e5795 rd96d9bc  
    5858#define getpagesize()  (PAGE_SIZE)
    5959
    60 extern char *getcwd(char *, size_t);
    61 extern int chdir(const char *);
    62 
    6360extern void exit(int) __attribute__((noreturn));
    6461extern int usleep(useconds_t);
  • uspace/lib/c/include/vfs/vfs.h

    r1e2e5795 rd96d9bc  
    7474
    7575extern char *vfs_absolutize(const char *, size_t *);
     76extern int vfs_cwd_set(const char *path);
     77extern int vfs_cwd_get(char *path, size_t);
    7678
    7779extern int vfs_fhandle(FILE *, int *);
  • uspace/lib/posix/source/unistd.c

    r1e2e5795 rd96d9bc  
    108108char *posix_getcwd(char *buf, size_t size)
    109109{
    110         char *p = getcwd(buf, size);
    111 
    112         if (p == NULL) {
    113                 errno = -errno;
     110        int rc = rcerrno(vfs_cwd_get, buf, size);
     111        if (rc != EOK)
    114112                return NULL;
    115         }
    116 
    117         return p;
     113        return buf;
    118114}
    119115
     
    125121int posix_chdir(const char *path)
    126122{
    127         return negerrno(chdir, path);
     123        int rc = rcerrno(vfs_cwd_set, path);
     124        if (rc != EOK)
     125                return -1;
     126        return 0;
    128127}
    129128
Note: See TracChangeset for help on using the changeset viewer.