Changeset 6afc9d7 in mainline for uspace/app/bdsh/cmds


Ignore:
Timestamp:
2015-10-06T19:01:36Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0328987
Parents:
f1f7584
Message:

UNIX-like I/O functions should use errno to return error code for many reasons.

Location:
uspace/app/bdsh/cmds
Files:
12 edited

Legend:

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

    rf1f7584 r6afc9d7  
    5757        previous_directory_set = true;
    5858
    59         int rc = chdir(new_dir);
    60         if (rc != EOK) {
    61                 return rc;
    62         }
     59        if (chdir(new_dir) != 0)
     60                return errno;
    6361
    6462        str_cpy(previous_directory, PATH_MAX, previous_directory_tmp);
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    rf1f7584 r6afc9d7  
    244244               
    245245                bytes = read(fd, buff + copied_bytes, bytes_to_read);
    246                 bytes += copied_bytes;
    247246                copied_bytes = 0;
    248247
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rf1f7584 r6afc9d7  
    2727 */
    2828
     29#include <errno.h>
    2930#include <stdio.h>
    3031#include <stdlib.h>
     
    8485        int r = stat(path, &s);
    8586
    86         if (r)
     87        if (r != 0)
    8788                return TYPE_NONE;
    8889        else if (s.is_directory)
     
    234235                         */
    235236                        if (force && !interactive) {
    236                                 if (unlink(dest_path)) {
     237                                if (unlink(dest_path) != 0) {
    237238                                        printf("Unable to remove %s\n",
    238239                                            dest_path);
     
    245246                                if (overwrite) {
    246247                                        printf("Overwriting file: %s\n", dest_path);
    247                                         if (unlink(dest_path)) {
     248                                        if (unlink(dest_path) != 0) {
    248249                                                printf("Unable to remove %s\n", dest_path);
    249250                                                goto exit;
     
    294295                                merge_paths(dest_path, PATH_MAX, src_dirname);
    295296
    296                                 if (mkdir(dest_path, 0) == -1) {
     297                                if (mkdir(dest_path, 0) != 0) {
    297298                                        printf("Unable to create "
    298299                                            "dest directory %s\n", dest_path);
     
    308309                         * e.g. cp -r /src /data/new_dir_src
    309310                         */
    310                         if (mkdir(dest_path, 0)) {
     311                        if (mkdir(dest_path, 0) != 0) {
    311312                                printf("Unable to create "
    312313                                    "dest directory %s\n", dest_path);
     
    405406        }
    406407
    407         while ((bytes = read_all(fd1, buff, blen)) > 0) {
    408                 if ((bytes = write_all(fd2, buff, bytes)) < 0)
     408        while ((bytes = read(fd1, buff, blen)) > 0) {
     409                if ((bytes = write(fd2, buff, bytes)) < 0)
    409410                        break;
    410411                copied += bytes;
     
    412413
    413414        if (bytes < 0) {
    414                 printf("\nError copying %s, (%d)\n", src, bytes);
     415                printf("\nError copying %s, (%d)\n", src, errno);
    415416                copied = bytes;
    416417        }
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    rf1f7584 r6afc9d7  
    3131 * As more stuff is completed and exposed in libc, this will improve */
    3232
     33#include <errno.h>
    3334#include <stdio.h>
    3435#include <stdlib.h>
     
    187188                if (rc != 0) {
    188189                        printf("ls: skipping bogus node %s\n", buff);
    189                         printf("rc=%d\n", rc);
     190                        printf("error=%d\n", errno);
    190191                        goto out;
    191192                }
     
    314315static unsigned int ls_scope(const char *path, struct dir_elem_t *de)
    315316{
    316         if (stat(path, &de->s)) {
     317        if (stat(path, &de->s) != 0) {
    317318                cli_error(CL_ENOENT, "%s", path);
    318319                return LS_BOGUS;
     
    376377                }
    377378        }
    378        
     379
    379380        argc -= optind;
    380        
     381
    381382        de.name = (char *) malloc(PATH_MAX);
    382383        if (!de.name) {
    383                 cli_error(CL_ENOMEM, "%s: ", cmdname);
     384                cli_error(CL_ENOMEM, "%s: Out of memory", cmdname);
    384385                return CMD_FAILURE;
    385386        }
    386387        memset(de.name, 0, PATH_MAX);
    387        
    388         if (argc == 0)
    389                 getcwd(de.name, PATH_MAX);
    390         else
     388
     389        if (argc == 0) {
     390                if (getcwd(de.name, PATH_MAX) == NULL) {
     391                        cli_error(CL_EFAIL, "%s: Failed determining working "
     392                            "directory", cmdname);
     393                        return CMD_FAILURE;
     394                }
     395        } else {
    391396                str_cpy(de.name, PATH_MAX, argv[optind]);
     397        }
    392398
    393399        scope = ls_scope(de.name, &de);
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    rf1f7584 r6afc9d7  
    8989{
    9090        /* Ensure we would always work with absolute and canonified path. */
    91         char *path = absolutize(user_path, NULL);
     91        char *path = vfs_absolutize(user_path, NULL);
    9292        if (path == NULL) {
    9393                cli_error(CL_ENOMEM, "%s: path too big?", cmdname);
     
    9595        }
    9696
    97         int rc;
    9897        int ret = 0;
    9998
    10099        if (!create_parents) {
    101                 rc = mkdir(path, 0);
    102                 if (rc != EOK) {
     100                if (mkdir(path, 0) != 0) {
    103101                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    104                             cmdname, path, str_error(rc));
     102                            cmdname, path, str_error(errno));
    105103                        ret = 1;
    106104                }
     
    137135                        char slash_char = path[prev_off];
    138136                        path[prev_off] = 0;
    139                         rc = mkdir(path, 0);
    140                         if (rc == EEXIST) {
    141                                 rc = EOK;
    142                         }
    143 
    144                         if (rc != EOK) {
     137
     138                        if (mkdir(path, 0) != 0 && errno != EEXIST) {
    145139                                cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    146                                     cmdname, path, str_error(rc));
     140                                    cmdname, path, str_error(errno));
    147141                                ret = 1;
    148142                                goto leave;
     
    152146                }
    153147                /* Create the final directory. */
    154                 rc = mkdir(path, 0);
    155                 if (rc != EOK) {
     148                if (mkdir(path, 0) != 0) {
    156149                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    157                             cmdname, path, str_error(rc));
     150                            cmdname, path, str_error(errno));
    158151                        ret = 1;
    159152                }
     
    214207
    215208        if (follow && (argv[optind] != NULL)) {
    216                 chdir(argv[optind]);
     209                if (chdir(argv[optind]) != 0)
     210                        printf("%s: Error switching to directory.", cmdname);
    217211        }
    218212
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rf1f7584 r6afc9d7  
    2727 */
    2828
     29#include <errno.h>
    2930#include <stdio.h>
    3031#include <stdlib.h>
     
    166167
    167168                if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)
    168                         goto exit;
     169                        goto error;
    169170
    170171                rc2 = write(fd, &byte, sizeof(char));
    171                 goto exit;
     172                if (rc2 < 0)
     173                        goto error;
     174                return CMD_SUCCESS;
    172175        }
    173176
     
    183186                rc = write(fd, buffer, to_write);
    184187                if (rc <= 0) {
    185                         printf("%s: Error writing file (%zd).\n", cmdname, rc);
     188                        printf("%s: Error writing file (%d).\n", cmdname, errno);
    186189                        close(fd);
    187190                        return CMD_FAILURE;
     
    191194
    192195        free(buffer);
    193 exit:
    194         rc = close(fd);
    195 
    196         if (rc != 0 || rc2 < 0) {
    197                 printf("%s: Error writing file (%zd).\n", cmdname, rc);
    198                 return CMD_FAILURE;
    199         }
     196
     197        if (close(fd) < 0)
     198                goto error;
    200199
    201200        return CMD_SUCCESS;
     201error:
     202        printf("%s: Error writing file (%d).\n", cmdname, errno);
     203        return CMD_FAILURE;
    202204}
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    rf1f7584 r6afc9d7  
    7272        int rc;
    7373
    74         get_mtab_list(&mtab_list);
     74        vfs_get_mtab_list(&mtab_list);
    7575
    7676        list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
     
    150150                mopts = t_argv[4];
    151151
    152         rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
     152        rc = vfs_mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
    153153        if (rc != EOK) {
    154154                printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n",
  • uspace/app/bdsh/cmds/modules/mv/mv.c

    rf1f7584 r6afc9d7  
    6060
    6161        rc = rename(argv[1], argv[2]);
    62         if (rc != EOK) {
    63                 printf("Unable to rename %s to %s (rc=%d)\n",
    64                     argv[1], argv[2], rc);
     62        if (rc != 0) {
     63                printf("Unable to rename %s to %s (error=%d)\n",
     64                    argv[1], argv[2], errno);
    6565                return CMD_FAILURE;
    6666        }
  • uspace/app/bdsh/cmds/modules/pwd/pwd.c

    rf1f7584 r6afc9d7  
    5656
    5757        memset(buff, 0, PATH_MAX);
    58         getcwd(buff, PATH_MAX);
    5958
    60         if (! buff) {
     59        if (getcwd(buff, PATH_MAX) == NULL) {
    6160                cli_error(CL_EFAIL,
    6261                        "Unable to determine the current working directory");
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    rf1f7584 r6afc9d7  
    2727 */
    2828
     29#include <errno.h>
    2930#include <stdio.h>
    3031#include <stdlib.h>
     
    131132static unsigned int rm_single(const char *path)
    132133{
    133         if (unlink(path)) {
     134        if (unlink(path) != 0) {
    134135                cli_error(CL_EFAIL, "rm: could not remove file %s", path);
    135136                return 1;
     
    150151
    151152        fd = open(path, O_RDONLY);
    152         if (fd > 0) {
     153        if (fd >= 0) {
    153154                close(fd);
    154155                return RM_FILE;
     
    210211        rc = rmdir(path);
    211212        if (rc == 0)
    212                 return ret;
     213                return errno;
    213214
    214215        cli_error(CL_ENOTSUP, "Can not remove %s", path);
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    rf1f7584 r6afc9d7  
    123123               
    124124                /* Check whether file exists if -c (--no-create) option is given */
    125                 if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == EOK)))
     125                if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == 0)))
    126126                        fd = open(buff, O_RDWR | O_CREAT);
    127127               
  • uspace/app/bdsh/cmds/modules/unmount/unmount.c

    rf1f7584 r6afc9d7  
    6666        }
    6767
    68         rc = unmount(argv[1]);
     68        rc = vfs_unmount(argv[1]);
    6969        if (rc != EOK) {
    7070                printf("Unable to unmount %s (rc=%d)\n", argv[1], rc);
Note: See TracChangeset for help on using the changeset viewer.