mirror of
https://github.com/troglobit/finit.git
synced 2026-11-10 16:31:21 +00:00
Minor optimization, drop expensive memset() ops
No need to zero out whole buffer for strlcat(), or other string check ops. Also drop a few completely useless memset() calls. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
d43af8c9c1
commit
c0716d7f63
4 files changed
+6
-10
No files matched your search
@@ -110,7 +110,7 @@ static int missing(char *job, char *id)
|
|||||||
|
|
||||||
static int do_query(char *buf, size_t len)
|
static int do_query(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
memset(query_buf, 0, sizeof(query_buf));
|
query_buf[0] = 0;
|
||||||
if (svc_parse_jobstr(buf, len, NULL, missing)) {
|
if (svc_parse_jobstr(buf, len, NULL, missing)) {
|
||||||
memcpy(buf, query_buf, len);
|
memcpy(buf, query_buf, len);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
+2
-2
@@ -357,7 +357,7 @@ char *lim2str(struct rlimit *rlim)
|
|||||||
char tmp[25];
|
char tmp[25];
|
||||||
static char buf[42];
|
static char buf[42];
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
buf[0] = 0;
|
||||||
if (RLIM_INFINITY == rlim->rlim_cur)
|
if (RLIM_INFINITY == rlim->rlim_cur)
|
||||||
snprintf(tmp, sizeof(tmp), "unlimited, ");
|
snprintf(tmp, sizeof(tmp), "unlimited, ");
|
||||||
else
|
else
|
||||||
@@ -661,7 +661,7 @@ static int parse_conf(char *file, int is_rcsd)
|
|||||||
/* Prepare default limits and group for each service in /etc/finit.d/ */
|
/* Prepare default limits and group for each service in /etc/finit.d/ */
|
||||||
if (is_rcsd) {
|
if (is_rcsd) {
|
||||||
memcpy(rlimit, global_rlimit, sizeof(rlimit));
|
memcpy(rlimit, global_rlimit, sizeof(rlimit));
|
||||||
memset(cgroup_current, 0, sizeof(cgroup_current));
|
cgroup_current[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_d("*** Parsing %s", file);
|
_d("*** Parsing %s", file);
|
||||||
|
|||||||
+2
-2
@@ -260,7 +260,7 @@ void print_banner(const char *heading)
|
|||||||
if (progress_style == PROGRESS_SILENT)
|
if (progress_style == PROGRESS_SILENT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
buf[0] = 0;
|
||||||
strlcat(buf, "\r\e[2K", sizeof(buf));
|
strlcat(buf, "\r\e[2K", sizeof(buf));
|
||||||
|
|
||||||
if (progress_style == PROGRESS_CLASSIC) {
|
if (progress_style == PROGRESS_CLASSIC) {
|
||||||
@@ -339,7 +339,7 @@ void printv(const char *fmt, va_list ap)
|
|||||||
|
|
||||||
delline();
|
delline();
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
buf[0] = 0;
|
||||||
len = print_timestamp(buf, sizeof(buf));
|
len = print_timestamp(buf, sizeof(buf));
|
||||||
vsnprintf(&buf[len], sizeof(buf) - len, fmt, ap);
|
vsnprintf(&buf[len], sizeof(buf) - len, fmt, ap);
|
||||||
|
|
||||||
|
|||||||
+1
-5
@@ -120,7 +120,6 @@ static int runlevel_get(int *prevlevel)
|
|||||||
int result;
|
int result;
|
||||||
struct init_request rq;
|
struct init_request rq;
|
||||||
|
|
||||||
memset(&rq, 0, sizeof(rq));
|
|
||||||
rq.cmd = INIT_CMD_GET_RUNLEVEL;
|
rq.cmd = INIT_CMD_GET_RUNLEVEL;
|
||||||
rq.magic = INIT_MAGIC;
|
rq.magic = INIT_MAGIC;
|
||||||
|
|
||||||
@@ -359,7 +358,7 @@ static char *svc_cond(svc_t *svc, char *buf, size_t len)
|
|||||||
{
|
{
|
||||||
char *cond, *conds;
|
char *cond, *conds;
|
||||||
|
|
||||||
memset(buf, 0, len);
|
buf[0] = 0;
|
||||||
|
|
||||||
if (!svc->cond[0])
|
if (!svc->cond[0])
|
||||||
return buf;
|
return buf;
|
||||||
@@ -485,10 +484,7 @@ int utmp_show(char *file)
|
|||||||
while ((ut = getutent())) {
|
while ((ut = getutent())) {
|
||||||
char addr[64];
|
char addr[64];
|
||||||
|
|
||||||
memset(id, 0, sizeof(id));
|
|
||||||
strlcpy(id, ut->ut_id, sizeof(id));
|
strlcpy(id, ut->ut_id, sizeof(id));
|
||||||
|
|
||||||
memset(user, 0, sizeof(user));
|
|
||||||
strlcpy(user, ut->ut_user, sizeof(user));
|
strlcpy(user, ut->ut_user, sizeof(user));
|
||||||
|
|
||||||
sec = ut->ut_tv.tv_sec;
|
sec = ut->ut_tv.tv_sec;
|
||||||
|
|||||||
Reference in new issue
Block a user