if ((fp = fopen("/proc/stat", "r")) == NULL) {
err = true;
- sprintf(err_msg, "can't read from /proc/stat with errno %d", errno);
+ snprintf(err_msg, sizeof(err_msg), "can't read from /proc/stat with errno %d", errno);
} else {
if (fscanf(fp, params, &cpu->utime, &cpu->ntime,
&cpu->stime, &cpu->itime, &cpu->iowtime, &cpu->irqtime,
int fd = open(path, O_WRONLY);
if (fd == -1) {
err = true;
- sprintf(err_msg, "Can't open %s. Error: %d", path, errno);
+ snprintf(err_msg, sizeof(err_msg), "Can't open %s. Error: %d", path, errno);
return -1;
}
const char* control = (enable?"1":"0");
}
err = true;
- sprintf(err_msg, "Error %d in writing to %s.", errno, path);
+ snprintf(err_msg, sizeof(err_msg), "Error %d in writing to %s.", errno, path);
}
close(fd);
return (err?-1:0);
*/
static void dfs_set_property(uint64_t mtag, const char* mapp, bool enable) {
char buf[64];
- snprintf(buf, 64, "%#" PRIx64, mtag);
+ snprintf(buf, sizeof(buf), "%#" PRIx64, mtag);
if (property_set(dfs_tags_property, buf) < 0) {
err = true;
- sprintf(err_msg, "Failed to set debug tags system properties.");
+ snprintf(err_msg, sizeof(err_msg), "Failed to set debug tags system properties.");
}
if (strlen(mapp) > 0
&& property_set(dfs_apps_property, mapp) < 0) {
err = true;
- sprintf(err_msg, "Failed to set debug applications.");
+ snprintf(err_msg, sizeof(err_msg), "Failed to set debug applications.");
}
if (log_sched) {
int fd = open(dfs_buffer_size_path, O_WRONLY);
if (fd == -1) {
err = true;
- sprintf(err_msg, "Can't open atrace buffer size file under /d/tracing.");
+ snprintf(err_msg, sizeof(err_msg), "Can't open atrace buffer size file under /d/tracing.");
return -1;
}
ssize_t len = strlen(buf_size_kb);
if (write(fd, buf_size_kb, len) != len) {
err = true;
- sprintf(err_msg, "Error in writing to atrace buffer size file.");
+ snprintf(err_msg, sizeof(err_msg), "Error in writing to atrace buffer size file.");
}
close(fd);
return (err?-1:0);