170
add_xnum_to_string(struct string *string, int xnum)
169
add_xnum_to_string(struct string *string, off_t xnum)
172
171
unsigned char suff[3] = "\0i";
175
174
/* XXX: I don't completely like the computation of d here. --pasky */
176
175
/* Mebi (Mi), 2^20 */
177
176
if (xnum >= 1024 * 1024) {
179
d = (xnum / (int) ((int) (1024 * 1024) / (int) 10)) % 10;
178
d = (xnum * (int) 10 / (int) ((int) (1024 * 1024))) % 10;
180
179
xnum /= 1024*1024;
181
180
/* Kibi (Ki), 2^10 */
182
181
} else if (xnum >= 1024) {
184
d = (xnum / (int) ((int) 1024 / (int) 10)) % 10;
183
d = (xnum * (int) 10 / (int) 1024) % 10;
187
assert(xnum == (long) xnum);
187
188
add_long_to_string(string, xnum);
189
190
if (xnum < 10 && d != -1) {
201
add_time_to_string(struct string *string, ttime time)
202
add_duration_to_string(struct string *string, long seconds)
203
204
unsigned char q[64];
209
if (time < 0) time = 0;
207
if (seconds < 0) seconds = 0;
212
if (time >= (24 * 3600)) {
213
ulongcat(q, &qlen, (time / (24 * 3600)), 5, 0);
210
if (seconds >= (24 * 3600)) {
211
ulongcat(q, &qlen, (seconds / (24 * 3600)), 5, 0);
218
216
/* Hours and minutes */
221
ulongcat(q, &qlen, (time / 3600), 4, 0);
217
if (seconds >= 3600) {
218
seconds %= (24 * 3600);
219
ulongcat(q, &qlen, (seconds / 3600), 4, 0);
223
ulongcat(q, &qlen, ((time / 60) % 60), 2, '0');
221
ulongcat(q, &qlen, ((seconds / 60) % 60), 2, '0');
225
223
/* Only minutes */
226
ulongcat(q, &qlen, (time / 60), 2, 0);
224
ulongcat(q, &qlen, (seconds / 60), 2, 0);
231
ulongcat(q, &qlen, (time % 60), 2, '0');
229
ulongcat(q, &qlen, (seconds % 60), 2, '0');
233
231
add_to_string(string, q);
236
add_timeval_to_string(struct string *string, timeval_T *timeval)
238
return add_duration_to_string(string, timeval_to_seconds(timeval));
237
241
#ifdef HAVE_STRFTIME
239
add_date_to_string(struct string *string, unsigned char *fmt, ttime *date)
243
add_date_to_string(struct string *string, unsigned char *fmt, time_t *date)
241
245
unsigned char buffer[MAX_STR_LEN];
242
ttime when_time = date ? *date : time(NULL);
246
time_t when_time = date ? *date : time(NULL);
243
247
struct tm *when_local = localtime(&when_time);
245
249
if (strftime(buffer, sizeof(buffer), fmt, when_local) <= 0)