filepath sub;
char sub_s[50];
const char *make_sub(const char *base) {
- sprintf(sub_s, "%s.%d", base, rand() % 100);
+ snprintf(sub_s, sizeof(sub_s), "%s.%d", base, rand() % 100);
string f = sub_s;
sub = cwd;
sub.push_dentry(f);
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <limits.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
int fd, err;
struct ceph_ioctl_layout l;
struct ceph_ioctl_dataloc dl;
- char *new_file_name = (char *)malloc(sizeof(char)*4096);
+ char new_file_name[PATH_MAX];
if (argc < 3) {
printf("usage: test_ioctls <filename> <offset>\n");
}
printf("set layout, creating file\n");
- sprintf(new_file_name, "%s/testfile", argv[3]);
+ snprintf(new_file_name, sizeof(new_file_name),
+ "%s/testfile", argv[3]);
fd = open(new_file_name, O_CREAT | O_RDWR, 0644);
if (fd < 0) {
perror("couldn't open file");
inline ostream& operator<<(ostream& out, const ceph_fsid& f) {
char b[37];
- sprintf(b, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ snprintf(b, sizeof(b), "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
f.fsid[0], f.fsid[1], f.fsid[2], f.fsid[3], f.fsid[4], f.fsid[5], f.fsid[6], f.fsid[7],
f.fsid[8], f.fsid[9], f.fsid[10], f.fsid[11], f.fsid[12], f.fsid[13], f.fsid[14], f.fsid[15]);
return out << b;
#ifndef CEPH_MDSTYPES_H
#define CEPH_MDSTYPES_H
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+#include <inttypes.h>
#include <math.h>
#include <ostream>
#include <set>
__u32 l = strlen(name) + 1;
char b[20];
if (snapid != CEPH_NOSNAP) {
- sprintf(b, "%llx", (long long unsigned)snapid);
+ uint64_t val(snapid);
+ snprintf(b, sizeof(b), "%" PRIx64, val);
l += strlen(b);
} else {
- strcpy(b, "head");
+ snprintf(b, sizeof(b), "%s", "head");
l += 4;
}
::encode(l, bl);
public:
MGenericMessage(int t) : Message(t) {
- sprintf(tname, "generic%d", get_type());
+ snprintf(tname, sizeof(tname), "generic%d", get_type());
}
//void set_pcid(long pcid) { this->pcid = pcid; }
}
bool exists_bl_sn(const char *a, version_t b) {
char bs[20];
- sprintf(bs, "%llu", (unsigned long long)b);
+ snprintf(bs, sizeof(bs), "%llu", (unsigned long long)b);
return exists_bl_ss(a, bs);
}
int get_bl_sn(bufferlist& bl, const char *a, version_t b) {
char bs[20];
- sprintf(bs, "%llu", (unsigned long long)b);
+ snprintf(bs, sizeof(bs), "%llu", (unsigned long long)b);
return get_bl_ss(bl, a, bs);
}
int put_bl_sn(bufferlist& bl, const char *a, version_t b, bool sync=true) {
char bs[20];
- sprintf(bs, "%llu", (unsigned long long)b);
+ snprintf(bs, sizeof(bs), "%llu", (unsigned long long)b);
return put_bl_ss(bl, a, bs, sync);
}
int erase_ss(const char *a, const char *b);
int erase_sn(const char *a, version_t b) {
char bs[20];
- sprintf(bs, "%llu", (unsigned long long)b);
+ snprintf(bs, sizeof(bs), "%llu", (unsigned long long)b);
return erase_ss(a, bs);
}
if (pg_sum.num_objects_degraded) {
double pc = (double)pg_sum.num_objects_degraded / (double)pg_sum.num_object_copies * (double)100.0;
char b[20];
- sprintf(b, "%.3lf", pc);
+ snprintf(b, sizeof(b), "%.3lf", pc);
out << "; " //<< pg_sum.num_objects_missing_on_primary << "/"
<< pg_sum.num_objects_degraded
<< "/" << pg_sum.num_object_copies << " degraded (" << b << "%)";
// dirs
void get_dir(string& dir) {
- char s[30];
- sprintf(s, "%d", whoami);
- dir = basedir + "/" + s;
+ dir = basedir + "/" + string(whoami);
}
void get_collfn(coll_t c, string &fn) {
char s[100];
- sprintf(s, "%d/%02llx/%016llx.co", whoami, BDBHASH_FUNC(c), c);
+ snprintf(s, sizeof(s), "%d/%02llx/%016llx.co", whoami, BDBHASH_FUNC(c), c);
fn = basedir + "/" + s;
}
#include "common/Timer.h"
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
{
char s[30];
int ret;
- sprintf(s, "%lld\n", (long long unsigned)seq);
+ snprintf(s, sizeof(s), "%" PRId64 "\n", seq);
ret = ::pwrite(fd, s, strlen(s), 0);
return ret;
}
utime_t start = g_clock.now();
for (uint64_t pos = 0; pos < count; pos += bsize) {
char nm[30];
- sprintf(nm, "disk_bw_test_%lld", (long long)pos);
+ snprintf(nm, sizeof(nm), "disk_bw_test_%lld", (long long)pos);
object_t oid(nm);
sobject_t soid(oid, 0);
ObjectStore::Transaction *t = new ObjectStore::Transaction;
static sobject_t get_osdmap_pobject_name(epoch_t epoch) {
char foo[20];
- sprintf(foo, "osdmap.%d", epoch);
+ snprintf(foo, sizeof(foo), "osdmap.%d", epoch);
return sobject_t(object_t(foo), 0);
}
static sobject_t get_inc_osdmap_pobject_name(epoch_t epoch) {
char foo[20];
- sprintf(foo, "inc_osdmap.%d", epoch);
+ snprintf(foo, sizeof(foo), "inc_osdmap.%d", epoch);
return sobject_t(object_t(foo), 0);
}
char hostname[30];
gethostname(hostname, sizeof(hostname)-1);
hostname[sizeof(hostname)-1] = 0;
- sprintf(s, "%s_%d_object%d", hostname, getpid(), objnum);
+ snprintf(s, sizeof(hostname), "%s_%d_object%d", hostname, getpid(), objnum);
}
int write_bench(Rados& rados, rados_pool_t pool,
bandwidth = ((double)data->finished)*((double)data->object_size)/(double)timePassed;
bandwidth = bandwidth/(1024*1024); // we want it in MB/sec
char bw[20];
- sprintf(bw, "%.3lf \n", bandwidth);
+ snprintf(bw, sizeof(bw), "%.3lf \n", bandwidth);
cout << "Total time run: " << timePassed << std::endl
<< "Total writes made: " << data->finished << std::endl
bandwidth = ((double)data->finished)*((double)data->object_size)/(double)runtime;
bandwidth = bandwidth/(1024*1024); // we want it in MB/sec
char bw[20];
- sprintf(bw, "%.3lf \n", bandwidth);
+ snprintf(bw, sizeof(bw), "%.3lf \n", bandwidth);
cout << "Total time run: " << runtime << std::endl
<< "Total reads made: " << data->finished << std::endl
ACLID id;
- sprintf(id.id, "%.16x", 0x1234);
+ snprintf(id.id, ID_SIZE + 1, "%.16x", 0x1234);
cout << "id=" << id.id << std::endl;
r = rados.exec(pool, oid, "acl", "get", bl, bl2);
*
*/
+#define __STDC_FORMAT_MACROS
#include "config.h"
#include "common/common_init.h"
#include "include/byteorder.h"
+#include <errno.h>
+#include <inttypes.h>
#include <iostream>
-
#include <stdlib.h>
-#include <time.h>
#include <sys/types.h>
-#include <errno.h>
+#include <time.h>
#include "include/rbd_types.h"
static string get_block_oid(rbd_obj_header_ondisk *header, uint64_t num)
{
char o[RBD_MAX_SEG_NAME_SIZE];
- sprintf(o, "%s.%012llx", header->block_name, (unsigned long long)num);
+ snprintf(o, RBD_MAX_SEG_NAME_SIZE,
+ "%s.%012" PRIx64, header->block_name, num);
return o;
}
for (int i=0; i<mb; i++) {
char f[30];
- sprintf(f, "foo%d\n", i);
+ snprintf(f, sizeof(f), "foo%d\n", i);
sobject_t soid(f, CEPH_NOSNAP);
t.write(coll_t(), soid, 0, bl.length(), bl);
}