From: Greg Farnum Date: Thu, 25 Aug 2011 19:22:02 +0000 (-0700) Subject: cephfs: use strtol instead of atoi; handle 0 properly X-Git-Tag: v0.35~215 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4dba8bc25e5aad93769e57389b297a11bfd183e8;p=ceph.git cephfs: use strtol instead of atoi; handle 0 properly Besides being generally better, this means we can accept pool 0 as the pool to store stuff in. Signed-off-by: Greg Farnum --- diff --git a/src/cephfs.cc b/src/cephfs.cc index c7b00c915e6e..70f433fef36e 100644 --- a/src/cephfs.cc +++ b/src/cephfs.cc @@ -188,7 +188,7 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, cerr << "Invalid option for command!" << endl; return 1; } - *stripe_unit = atoi(argv[i+1]); + *stripe_unit = strtol(argv[i+1], NULL, 0); if (!*stripe_unit) { cerr << "invalid value for stripe unit" << endl; return 1; @@ -198,7 +198,7 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, cerr << "Invalid option for command!" << endl; return 1; } - *stripe_count = atoi(argv[i+1]); + *stripe_count = strtol(argv[i+1], NULL, 0); if (!*stripe_count) { cerr << "invalid value for stripe count" << endl; return 1; @@ -208,7 +208,7 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, cerr << "Invalid option for command!" << endl; return 1; } - *object_size = atoi(argv[i+1]); + *object_size = strtol(argv[i+1], NULL, 0); if (!*object_size) { cerr << "invalid value for object size" << endl; return 1; @@ -218,8 +218,9 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, cerr << "Invalid option for command!" << endl; return 1; } - *pool= atoi(argv[i+1]); - if (!*pool) { + errno = 0; + *pool= strtol(argv[i+1], NULL, 0); + if (!*pool && errno) { cerr << "invalid value for pool" << endl; return 1; } @@ -228,8 +229,9 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, cerr << "Invalid option for command!" << endl; return 1; } - *osd = atoi(argv[i+1]); - if (!*osd) { + errno = 0; + *osd = strtol(argv[i+1], NULL, 0); + if (!*osd && errno) { cerr << "invalid value for osd" << endl; return 1; } @@ -238,8 +240,9 @@ int init_options(int argc, char **argv, int *fd, char **path, int *cmd, cerr << "Invalid option for command!" << endl; return 1; } - *file_offset = atoi(argv[i+1]); - if (!*file_offset) { + errno = 0; + *file_offset = strtol(argv[i+1], NULL, 0); + if (!*file_offset && errno) { cerr << "invalid value for offset" << endl; return 1; }