Optimize `createCron` logic
replace `scope_memset`, `scope_snprintf`,
`scope_strlen` calls with simplified handling
const string
@@ -397,38 +397,24 @@ createCron(const char *scopePath, const char* filterPath) {
return FALSE;
}
- scope_memset(path, 0, PATH_MAX);
// Create the cron entry
- if (scope_snprintf(path, sizeof(path), SCOPE_CRON_PATH) < 0) {
- scope_perror("createCron: cron: error: snprintf() failed\n");
- scope_fprintf(scope_stderr, "path: %s\n", path);
- return FALSE;
- }
-
- scope_memset(buf, 0, 1024);
- if (scope_snprintf(buf, sizeof(buf), SCOPE_CRONTAB) < 0) {
- scope_perror("createCron: cron: error: snprintf() failed\n");
- scope_fprintf(scope_stderr, "path: %s\n", path);
- return FALSE;
- }
-
- if ((outFd = scope_open(path, O_RDWR | O_CREAT, 0775)) == -1) {
+ if ((outFd = scope_open(SCOPE_CRON_PATH, O_RDWR | O_CREAT, 0775)) == -1) {
scope_perror("createCron: cron: scope_open failed");
- scope_fprintf(scope_stderr, "path: %s\n", path);
+ scope_fprintf(scope_stderr, "path: %s\n", SCOPE_CRON_PATH);
return FALSE;
}
// crond will detect this file entry and run on its' next cycle
- if (scope_write(outFd, buf, scope_strlen(buf)) == -1) {
+ if (scope_write(outFd, SCOPE_CRONTAB, sizeof(SCOPE_CRONTAB) - 1) == -1) {
scope_perror("createCron: cron: scope_write failed");
- scope_fprintf(scope_stderr, "path: %s\n", path);
+ scope_fprintf(scope_stderr, "path: %s\n", SCOPE_CRON_PATH);
scope_close(outFd);
return FALSE;
}
if (scope_close(outFd) == -1) {
scope_perror("createCron: cron: scope_close failed");
- scope_fprintf(scope_stderr, "path: %s\n", path);
+ scope_fprintf(scope_stderr, "path: %s\n", SCOPE_CRON_PATH);
return FALSE;
}
