PERFORCE change 147225 for review
Anders Nore
andenore at FreeBSD.org
Tue Aug 12 11:52:27 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=147225
Change 147225 by andenore at andenore_laptop on 2008/08/12 11:52:26
Integrated changes and got rid of all compiler warnings. printHumanReadable changed name to
getHumanReadable and uses libutil's humanize_number instead of my own implementation, getting the
same functionality with less code :)
Affected files ...
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile.inc#3 integrate
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#9 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/converter.h#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#7 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#11 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#9 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/main.c#6 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#9 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#12 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/date.c#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/file.c#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#15 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/pen.c#2 integrate
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#10 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/str.c#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/url.c#6 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/perform.c#6 edit
Differences ...
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile.inc#3 (text+ko) ====
@@ -1,9 +1,12 @@
-# $FreeBSD: src/usr.sbin/pkg_install/Makefile.inc,v 1.16 2008/05/03 23:17:37 pav Exp $
+# $FreeBSD: src/usr.sbin/pkg_install/Makefile.inc,v 1.17 2008/08/07 14:48:35 phk Exp $
.include <bsd.own.mk>
LIBINSTALL= ${.OBJDIR}/../lib/libinstall.a
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
+
.if ${MK_OPENSSL} != "no" && \
defined(LDADD) && ${LDADD:M-lfetch} != ""
DPADD+= ${LIBSSL} ${LIBCRYPTO}
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#9 (text+ko) ====
@@ -457,24 +457,9 @@
/* Time to record the deed? */
if (!NoRecord && !Fake) {
char contents[FILENAME_MAX];
- char **depnames = NULL, **deporigins = NULL, ***depmatches, *tmp;
+ char **depnames = NULL, **deporigins = NULL, ***depmatches;
int i, dep_count = 0;
FILE *contfile;
- struct stat stat_s;
-
-// tmp = LOG_DIR;
-// (void) stat(tmp, &stat_s);
-// if (getuid() && geteuid() != stat_s.st_uid) {
-// if (!Force) {
-// if (getuid() == 0)
-// errx(1, "you do not own %s, use -R to not register this package", tmp);
-// else
-// errx(1, "you do not own %s, use -R or perhaps become root?", tmp);
-//
-// goto fail;
-// } else
-// warnx("you do not own %s (proceeding anyways)", tmp);
-// }
if (getuid() != 0)
warnx("not running as root - trying to record install anyway");
@@ -495,7 +480,7 @@
* Reconstructs +REQUIRED_BY file for the package to be installed in
* case it has been removed earlier (e.g. pkg_delete -f)
*/
- fix_dependencies(Plist.name);
+ fix_dependencies((char *)Plist.name);
/* Make sure pkg_info can read the entry */
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/converter.h#5 (text+ko) ====
@@ -28,4 +28,6 @@
extern Boolean CacheAllDates;
extern char * Key;
-#endif /* _INST_CONVERTER_H */+void usage(void);
+
+#endif /* _INST_CONVERTER_H */
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#7 (text+ko) ====
@@ -23,12 +23,12 @@
#include <stdlib.h>
#include <lib.h>
#include <getopt.h>
+#include <err.h>
Boolean CheckExists = FALSE;
Boolean Print = FALSE;
Boolean Textual = FALSE;
Boolean CacheAllDates = FALSE;
-void usage(void);
static char opts[] = "vdthep";
@@ -40,6 +40,7 @@
{ NULL, 0, NULL, 0 }
};
+void usage(void);
int
main(int argc, char **argv) {
@@ -112,7 +113,7 @@
}
void
-usage()
+usage(void)
{
fprintf(stderr, "usage:\t%s\n\t%s\n",
"pkg_convert [-vtep] [keys ...]",
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#11 (text+ko) ====
@@ -56,7 +56,7 @@
else
printf("%s\n", exists ? "1" : "0");
- *pkgs++;
+ pkgs++;
}
return 0;
@@ -72,7 +72,7 @@
else
printf("%-18s: (null) does not exist\n", *pkgs);
- *pkgs++;
+ pkgs++;
}
} else {
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#9 (text+ko) ====
@@ -243,10 +243,11 @@
*/
if (PlistOnly) {
if (openDatabase(O_CREAT | O_RDWR))
- err("Could not open database: %s", DBCACHE_FILE);
+ err(1, "Could not open database: %s", (char *)DBCACHE_FILE);
+
Boolean v = Verbose;
Verbose = FALSE;
- fix_dependencies(plist.name);
+ fix_dependencies((char *)plist.name);
Verbose = v;
plist_add_installtime(&plist);
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/main.c#6 (text+ko) ====
@@ -156,13 +156,14 @@
if(cacheExists()) {
openDatabase(O_RDWR);
- if (errno == EACCES)
+ if (errno == EACCES) {
if (openDatabase(O_RDONLY))
warn("Could not open database");
else {
warnx("you do not own dbcache: %s %s",
DBCACHE_FILE, Force ? "(proceeding anyways)" : "");
}
+ }
atexit(closeDatabase);
}
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#9 (text+ko) ====
@@ -309,7 +309,7 @@
if (UseBlkSz)
printf("%lu\t(%s)\n", howmany(size, blksize), descr);
else {
- printf("%s\n", printHumanReadable(size));
+ printf("%s\n", getHumanReadable(size));
}
} else
if (UseBlkSz)
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#12 (text+ko) ====
@@ -21,11 +21,14 @@
#include "lib.h"
#include <assert.h>
+#include <err.h>
int compare_func(const DBT *, const DBT *);
+DB *opendb(const char *, int);
int closedb(DB *db);
int dbput(const DB *db, DBT *key, DBT *data);
-
+int dbget(const DB *db, DBT *key, DBT *data);
+int dbscan(const DB *db, DBT *key, DBT *data);
/*
* Btree information structure
@@ -318,7 +321,7 @@
/* Cache installtime */
if (pkg->datetime != NULL) {
- szTime = pkg->datetime;
+ szTime = (char *)pkg->datetime;
} else if (cacheAllDates) {
char path[PATH_MAX];
snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, pkg->name, COMMENT_FNAME);
@@ -328,8 +331,8 @@
}
char tmp[128], tmp2[128];
- snprintf(&tmp, sizeof(tmp), "+D%s", pkg->name);
- snprintf(&tmp2, sizeof(tmp2), "%s", szTime);
+ snprintf((char *)&tmp, sizeof(tmp), "+D%s", pkg->name);
+ snprintf((char *)&tmp2, sizeof(tmp2), "%s", szTime);
key.size = strlen(tmp) + 1;
key.data = (char *)tmp;
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/date.c#4 (text+ko) ====
@@ -20,7 +20,8 @@
*/
#include "lib.h"
-
+#include <err.h>
+
/*
* getInstallDate - gets the installdate for pkgname if it exists
* If successful returns second-since-epoch of the installdate otherwise
@@ -61,8 +62,8 @@
warn("Could not open %s", path);
return -1;
}
- read_plist(&plist, fp);
- data.data = plist.datetime;
+ read_plist((Package *)&plist, fp);
+ data.data = (char *)plist.datetime;
}
if (data.data == NULL)
@@ -72,7 +73,7 @@
return getTime(year, month, day, hour, minute, second);
} else {
warnx("%u-%u-%u %u:%u", year, month, day, hour, minute, second);
- warnx("Invalid datetime format: %s", data.data);
+ warnx("Invalid datetime format: %s", (char *)data.data);
return -1;
}
}
@@ -154,8 +155,8 @@
static char timeString[80];
installTime = localtime(&clock);
- snprintf(&timeString, sizeof(timeString), "%u-%02u-%02u %02u:%02u:%02u",
+ snprintf((char *)&timeString, sizeof(timeString), "%u-%02u-%02u %02u:%02u:%02u",
installTime->tm_year + 1900, installTime->tm_mon + 1, installTime->tm_mday,
installTime->tm_hour, installTime->tm_min, installTime->tm_sec);
return timeString;
-}+}
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/file.c#5 (text+ko) ====
@@ -27,12 +27,6 @@
#include <time.h>
#include <sys/wait.h>
-char sizeTable[][5] = { "Byte", "kB", "MB", "GB", "TB" };
-
-int power(int , int);
-char *printHumanReadable(unsigned int);
-unsigned int human_readable(unsigned int, int *, unsigned int, int *);
-
/* Quick check to see if a file exists */
Boolean
fexists(const char *fname)
@@ -432,62 +426,5 @@
*buf = '\0';
}
-int
-power(int base, int n)
-{
- int i;
-
- for (i = 1; i<n; i++)
- base *= base;
-
- return base;
-}
-
-/* Converts size in bytes to human readable output (kB, MB, GB, ...) returns an
- * integer which is size/(1024 * index), so the index shows of which magnitude
- * the result is. The precision (numbers behind .) is returned in precision
- * (not entirely accurate and this can be NULL).
- * Make sure the index passed to this function is correct, or else you will get
- * a wrong result, i.e. if size is in bytes use index=0, if in kB use index=1 ..
- * num is the accuracy you want (the count of numbers after . )
- */
-unsigned int
-human_readable(unsigned int size, int *precision, unsigned int num, int *index)
-{
- if (size >= 1024) {
- if (precision)
- *precision = (size % 1024);
- *index = *index + 1;
- return human_readable(size/1024, precision, num, index);
- }
-
- if (precision) {
- if (num <= 0)
- num = 1;
-
- *precision = (*precision * power(10, num));
- *precision /= 1024;
- }
-
- return size;
-}
-
-char *
-printHumanReadable(unsigned int size)
-{
- static char result[32];
- unsigned int index = 0;
- int tmpSize = 0, precision = 0;
-
- tmpSize = human_readable(size, &precision, 1, &index);
- snprintf(result, PATH_MAX, "%d.%01d ", tmpSize, precision);
-
- if (index > sizeof(sizeTable))
- warnx("printHumanReadable: sizeTable out of bounds");
- else
- strcat(result, sizeTable[index]);
-
- return result;
-}
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#15 (text+ko) ====
@@ -185,6 +185,7 @@
char *get_string(char *, int, FILE *);
char **get_string_array(char *str, char delim);
void free_string_array(char **str_arr);
+char *getHumanReadable(unsigned int);
/* File */
Boolean fexists(const char *);
@@ -254,7 +255,7 @@
int version_cmp(const char *, const char *);
/* Database */
-Boolean cacheExists();
+Boolean cacheExists(void);
int openDatabase(int flags);
int dbsave(const DBT *key, const DBT *data);
int dbAddPackage(const char *pkgname, const char *pkgdata);
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/pen.c#2 (text+ko) ====
@@ -19,10 +19,11 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/lib/pen.c,v 1.42 2004/07/28 16:03:13 stefanf Exp $");
+__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/lib/pen.c,v 1.43 2008/08/07 14:48:35 phk Exp $");
#include "lib.h"
#include <err.h>
+#include <libutil.h>
#include <libgen.h>
#include <sys/signal.h>
#include <sys/param.h>
@@ -44,6 +45,7 @@
{
char *cp;
struct stat sb;
+ char humbuf[6];
if (pen[0] && isdir(dirname(pen)) == TRUE && (min_free(dirname(pen)) >= sz))
return pen;
@@ -59,10 +61,12 @@
strcpy(pen, "/usr/tmp/instmp.XXXXXX");
else {
cleanup(0);
+ humanize_number(humbuf, sizeof humbuf, sz, "", HN_AUTOSCALE,
+ HN_NOSPACE);
errx(2,
"%s: can't find enough temporary space to extract the files, please set your\n"
-"PKG_TMPDIR environment variable to a location with at least %ld bytes\n"
-"free", __func__, (long)sz);
+"PKG_TMPDIR environment variable to a location with at least %s bytes\n"
+"free", __func__, humbuf);
return NULL;
}
return pen;
@@ -98,6 +102,8 @@
char *
make_playpen(char *pen, off_t sz)
{
+ char humbuf1[6], humbuf2[6];
+
if (!find_play_pen(pen, sz))
return NULL;
@@ -111,8 +117,13 @@
}
if (Verbose) {
- if (sz)
- fprintf(stderr, "Requested space: %d bytes, free space: %lld bytes in %s\n", (int)sz, (long long)min_free(pen), pen);
+ if (sz) {
+ humanize_number(humbuf1, sizeof humbuf1, sz, "", HN_AUTOSCALE,
+ HN_NOSPACE);
+ humanize_number(humbuf2, sizeof humbuf2, min_free(pen),
+ "", HN_AUTOSCALE, HN_NOSPACE);
+ fprintf(stderr, "Requested space: %s bytes, free space: %s bytes in %s\n", humbuf1, humbuf2, pen);
+ }
}
if (min_free(pen) < sz) {
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#10 (text+ko) ====
@@ -311,9 +311,9 @@
}
if (cmd == PLIST_COMMENT && sscanf(cp, "DATE:%s %s\n", (char *)&date, (char *)&time) == 2) {
pkg->datetime = malloc(strlen(date) + strlen(time) + 1);
- strncat(pkg->datetime, (const char *)date, sizeof(date));
- strncat(pkg->datetime, (const char *) " ", 1);
- strncat(pkg->datetime, (const char *)time, sizeof(time));
+ strncat((char *)pkg->datetime, (const char *)date, sizeof(date));
+ strncat((char *)pkg->datetime, (const char *) " ", 1);
+ strncat((char *)pkg->datetime, (const char *)time, sizeof(time));
goto bottom;
}
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/str.c#4 (text+ko) ====
@@ -22,6 +22,9 @@
__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/lib/str.c,v 1.15 2003/05/26 17:12:22 lioux Exp $");
#include "lib.h"
+#include <libutil.h>
+
+int count_chars(const char *, char);
char *
strconcat(const char *s1, const char *s2)
@@ -177,4 +180,19 @@
return;
}
+/*
+ * getHumanReadable gets a human readable string
+ * representation of size, which is the size in bytes
+ */
+char *
+getHumanReadable(unsigned int size)
+{
+ static char result[8];
+
+ humanize_number((char *)&result, sizeof(result), size, (const char *)"", HN_AUTOSCALE, HN_DECIMAL);
+ strcat(result, "B");
+
+ return result;
+}
+
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/url.c#6 (text+ko) ====
@@ -132,7 +132,7 @@
if (isatty(0) || Verbose) {
printf("Fetching %s from %s...\n",
- gotStat ? (char *)printHumanReadable(fileSize) : "", fname);
+ gotStat ? (char *)getHumanReadable(fileSize) : "", fname);
fflush(stdout);
}
pen[0] = '\0';
@@ -202,12 +202,12 @@
if (strippedName)
strippedName++;
- snprintf(progress, sizeof(progress), "%s", (char *)printHumanReadable(count));
+ snprintf(progress, sizeof(progress), "%s", (char *)getHumanReadable(count));
int perc = (int)count*100 / fileSize;
snprintf(tmpString, sizeof(tmpString),
"%3i%% of %*s %*sps",
gotStat ? perc : 100, 9, progress, 9,
- (char *)printHumanReadable(dspeed ? dspeed : acc));
+ (char *)getHumanReadable(dspeed ? dspeed : acc));
if (isatty(0) || Verbose)
printf("%s %*s ", strippedName ? strippedName : "", cols - (strlen(strippedName)+2), tmpString);
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/perform.c#6 (text+ko) ====
@@ -142,7 +142,7 @@
if(CacheExists) {
plist.name = pkg;
- char *origin = dbgetdata(pkg);
+ char *origin = (char *)dbgetdata(pkg);
printf("pkg = %s -> origin = %s\n", pkg, origin);
plist.origin = origin;
} else {
More information about the p4-projects
mailing list