Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 269123
Collapse All | Expand All

(-)qmailadmin-1.2.12/util.c (-18 / +48 lines)
Lines 19-28 Link Here
19
19
20
#include <stdio.h>
20
#include <stdio.h>
21
#include <stdlib.h>
21
#include <stdlib.h>
22
#include <stddef.h>
23
#include <errno.h>
22
#include <string.h>
24
#include <string.h>
23
#include <unistd.h>
25
#include <unistd.h>
24
#include <sys/stat.h>
26
#include <sys/stat.h>
25
#include <unistd.h>
26
#include <pwd.h>
27
#include <pwd.h>
27
#include <dirent.h>
28
#include <dirent.h>
28
#include <ctype.h>
29
#include <ctype.h>
Lines 352-392 char *get_quota_used(char *dir) { Link Here
352
                   back to bytes for vpasswd file
353
                   back to bytes for vpasswd file
353
   return value: 0 for success, 1 for failure
354
   return value: 0 for success, 1 for failure
354
*/
355
*/
355
int quota_to_bytes(char returnval[], char *quota) {
356
int quota_to_bytes(char returnval[], const char *quota) {
356
    double tmp;
357
    double tmp;
358
    int err = 0;
357
359
358
    if (quota == NULL) { return 1; }
360
    if (quota == NULL) { return 1; }
359
    if ((tmp = atof(quota))) {
361
360
        tmp *= 1048576;
362
    /* first set errno to 0 to determine if an error occurs */
361
        sprintf(returnval, "%.0lf", tmp);
363
    errno = 0;
362
        return 0;
364
    tmp = strtod(quota, NULL);
365
    err = errno;
366
    if (err != 0) {
367
        perror("quota_to_bytes");
368
        return 1;
363
    } else {
369
    } else {
364
	strcpy (returnval, "");
370
        tmp *= (1024*1024);
365
	return 1;
371
        err = sprintf(returnval, "%.0lf", tmp);
372
        if (err > 0) {
373
            return 0;
374
        } else {
375
            returnval[0] = '\0';
376
            return 1;
377
        }
366
    }
378
    }
367
}
379
}
368
/* quota_to_megabytes: used to convert vpasswd representation of quota
380
/* quota_to_megabytes: used to convert vpasswd representation of quota
369
                       to number of megabytes.
381
                       to number of megabytes.
370
   return value: 0 for success, 1 for failure
382
   return value: 0 for success, 1 for failure
371
*/
383
*/
372
int quota_to_megabytes(char *returnval, char *quota) {
384
int quota_to_megabytes(char *returnval, const char *quota) {
373
    double tmp;
385
    double tmp;
374
    int i;
386
    int err = 0;
387
    size_t i;
375
388
376
    if (quota == NULL) { return 1; }
389
    if (quota == NULL) { return 1; }
377
    i = strlen(quota);
390
    i = strlen(quota);
391
392
    errno = 0;
393
    tmp = strtod(quota, NULL);
394
    err = errno;
395
    if (err != 0) {
396
        perror("quota_to_megabytes");
397
        return 1;
398
    }
399
378
    if ((quota[i-1] == 'M') || (quota[i-1] == 'm')) {
400
    if ((quota[i-1] == 'M') || (quota[i-1] == 'm')) {
379
        tmp = atol(quota);  /* already in megabytes */
401
        /* already in megabytes */
380
    } else if ((quota[i-1] == 'K') || (quota[i-1] == 'k')) {
402
    } else if ((quota[i-1] == 'K') || (quota[i-1] == 'k')) {
381
	tmp = atol(quota) * 1024;  /* convert kilobytes to megabytes */
403
        /* convert kilobytes to megabytes */
382
    } else if ((tmp = atol(quota))) {
404
        tmp *= 1024;
383
        tmp /= 1048576.0;
405
    } else if (tmp != 0) {
406
        /* convert bytes to megabytes */
407
        tmp /= (1024*1024);
384
    } else {
408
    } else {
385
	strcpy (returnval, "");
409
        returnval[0] = '\0';
386
	return 1;
410
        return 1;
411
    }
412
413
    err = sprintf(returnval, "%.2lf", tmp);
414
    if (err > 0) {
415
        return 0;
416
    } else {
417
        returnval[0] = '\0';
418
        return 1;
387
    }
419
    }
388
    sprintf(returnval, "%.2lf", tmp);
389
    return 0;
390
}
420
}
391
421
392
void print_user_index (char *action, int colspan, char *user, char *dom, time_t mytime)
422
void print_user_index (char *action, int colspan, char *user, char *dom, time_t mytime)
(-)qmailadmin-1.2.12/util.h (-2 / +2 lines)
Lines 25-32 void str_replace (char *, char, char); Link Here
25
25
26
void qmail_button(char *modu, char *command, char *user, char *dom, time_t mytime, char *png);
26
void qmail_button(char *modu, char *command, char *user, char *dom, time_t mytime, char *png);
27
27
28
int quota_to_bytes(char[], char*);     //jhopper prototype
28
int quota_to_bytes(char[], const char*);     //jhopper prototype
29
int quota_to_megabytes(char[], char*); //jhopper prototype
29
int quota_to_megabytes(char[], const char*); //jhopper prototype
30
30
31
void print_user_index (char *action, int colspan, char *user, char *dom, time_t mytime);
31
void print_user_index (char *action, int colspan, char *user, char *dom, time_t mytime);
32
char *cgiurl (char *action);
32
char *cgiurl (char *action);

Return to bug 269123