From 94d7b17c9e04c2e5ff887af916d66b7ee5194864 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 16 Dec 2009 09:25:55 +0200 Subject: Simplify fsmFsPath() --- lib/fsm.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lib/fsm.c') diff --git a/lib/fsm.c b/lib/fsm.c index 071f2144b..761b12763 100644 --- a/lib/fsm.c +++ b/lib/fsm.c @@ -111,19 +111,12 @@ static char * fsmFsPath(const FSM_t fsm, char * s = NULL; if (fsm) { - size_t nb; - char * t; - nb = strlen(fsm->dirName) + - (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) + - (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) + - strlen(fsm->baseName) + 1; - s = t = xmalloc(nb); - t = stpcpy(t, fsm->dirName); - if (st && !S_ISDIR(st->st_mode)) - if (subdir) t = stpcpy(t, subdir); - t = stpcpy(t, fsm->baseName); - if (st && !S_ISDIR(st->st_mode)) - if (suffix) t = stpcpy(t, suffix); + int isDir = (st && S_ISDIR(st->st_mode)); + s = rstrscat(NULL, fsm->dirName, + (!isDir && subdir) ? subdir : "", + fsm->baseName, + (!isDir && suffix) ? suffix : "", + NULL); } return s; } -- cgit v1.2.3