summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/shared.c b/shared.c
index 7ec2e19..3926b4a 100644
--- a/shared.c
+++ b/shared.c
@@ -79,65 +79,57 @@ struct cgit_repo *cgit_get_repoinfo(const char *url)
79 for (i=0; i<cgit_repolist.count; i++) { 79 for (i=0; i<cgit_repolist.count; i++) {
80 repo = &cgit_repolist.repos[i]; 80 repo = &cgit_repolist.repos[i];
81 if (!strcmp(repo->url, url)) 81 if (!strcmp(repo->url, url))
82 return repo; 82 return repo;
83 } 83 }
84 return NULL; 84 return NULL;
85} 85}
86 86
87void *cgit_free_commitinfo(struct commitinfo *info) 87void *cgit_free_commitinfo(struct commitinfo *info)
88{ 88{
89 free(info->author); 89 free(info->author);
90 free(info->author_email); 90 free(info->author_email);
91 free(info->committer); 91 free(info->committer);
92 free(info->committer_email); 92 free(info->committer_email);
93 free(info->subject); 93 free(info->subject);
94 free(info->msg); 94 free(info->msg);
95 free(info->msg_encoding); 95 free(info->msg_encoding);
96 free(info); 96 free(info);
97 return NULL; 97 return NULL;
98} 98}
99 99
100char *trim_end(const char *str, char c) 100char *trim_end(const char *str, char c)
101{ 101{
102 int len; 102 int len;
103 char *s, *t;
104 103
105 if (str == NULL) 104 if (str == NULL)
106 return NULL; 105 return NULL;
107 t = (char *)str; 106 len = strlen(str);
108 len = strlen(t); 107 while(len > 0 && str[len - 1] == c)
109 while(len > 0 && t[len - 1] == c)
110 len--; 108 len--;
111
112 if (len == 0) 109 if (len == 0)
113 return NULL; 110 return NULL;
114 111 return xstrndup(str, len);
115 c = t[len];
116 t[len] = '\0';
117 s = xstrdup(t);
118 t[len] = c;
119 return s;
120} 112}
121 113
122char *strlpart(char *txt, int maxlen) 114char *strlpart(char *txt, int maxlen)
123{ 115{
124 char *result; 116 char *result;
125 117
126 if (!txt) 118 if (!txt)
127 return txt; 119 return txt;
128 120
129 if (strlen(txt) <= maxlen) 121 if (strlen(txt) <= maxlen)
130 return txt; 122 return txt;
131 result = xmalloc(maxlen + 1); 123 result = xmalloc(maxlen + 1);
132 memcpy(result, txt, maxlen - 3); 124 memcpy(result, txt, maxlen - 3);
133 result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; 125 result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.';
134 result[maxlen] = '\0'; 126 result[maxlen] = '\0';
135 return result; 127 return result;
136} 128}
137 129
138char *strrpart(char *txt, int maxlen) 130char *strrpart(char *txt, int maxlen)
139{ 131{
140 char *result; 132 char *result;
141 133
142 if (!txt) 134 if (!txt)
143 return txt; 135 return txt;