MCPcopy Create free account
hub / github.com/coreutils/coreutils / create_fullname

Function create_fullname

src/pinky.c:112–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110 this function. */
111
112static char *
113create_fullname (char const *gecos_name, char const *user_name)
114{
115 idx_t rsize = strlen (gecos_name) + 1;
116 idx_t ampersands = count_ampersands (gecos_name);
117
118 if (ampersands != 0)
119 {
120 idx_t ulen = strlen (user_name);
121 ptrdiff_t product;
122 if (ckd_mul (&product, ulen - 1, ampersands)
123 || ckd_add (&rsize, rsize, product))
124 xalloc_die ();
125 }
126
127 char *result = xmalloc (rsize);
128 char *r = result;
129
130 while (*gecos_name)
131 {
132 if (*gecos_name == '&')
133 {
134 char const *uname = user_name;
135 if (islower (to_uchar (*uname)))
136 *r++ = toupper (to_uchar (*uname++));
137 while (*uname)
138 *r++ = *uname++;
139 }
140 else
141 {
142 *r++ = *gecos_name;
143 }
144
145 gecos_name++;
146 }
147 *r = 0;
148
149 return result;
150}
151
152/* Return a string representing the time between WHEN and the time
153 that this function is first run. */

Callers 2

print_entryFunction · 0.85
print_long_entryFunction · 0.85

Calls 3

count_ampersandsFunction · 0.85
xalloc_dieFunction · 0.85
to_ucharFunction · 0.85

Tested by

no test coverage detected