Mercurial > gftp.yaz
diff lib/misc.c @ 87:6df043359b41
2003-1-11 Brian Masney <masneyb@gftp.org>
* autogen.sh - removed --intl and --no-changelog flags to gettextize
* aclocal.m4 - updated
* configure.in - and intl and po directories to AC_OUTPUT
* cvsclean - remove more stuff
* lib/bookmark.c (bookmark_parse_url) - use gftp_parse_bookmark
function
* lib/cache.c - remove gftp_cache_get_url_prefix(). Use
request->url_prefix instead
* lib/config_file.c - use proper exit codes. Also complain if the
default protocol specified in the config file is invalid
* lib/gftp.h lib/local.c lib/protocols.c - removed isblock, ischar,
issocket and isfifo in struct gftp_file (not used anymore)
* lib/gftp.h lib/misc.c - removed file_countlf (not used anymore)
* lib/local.c lib/misc.c lib/protocols.c - various small cleanups
* lib/misc.c (string_hash_function) - check key[i] instead of key[0]
* lib/protocols.c lib/gftp.h - added gftp_parse_bookmark()
* lib/rfc2068.c - if we are connected to a FTP url via a proxy, set
request->url_prefix to be ftp. Added rfc2068_destroy() to free
url_prefix whenever the structure is to be freed
author | masneyb |
---|---|
date | Sat, 11 Jan 2003 15:47:09 +0000 |
parents | 7ef60ce2bdb2 |
children | 3b573c8ef706 |
line wrap: on
line diff
--- a/lib/misc.c Mon Dec 30 01:32:19 2002 +0000 +++ b/lib/misc.c Sat Jan 11 15:47:09 2003 +0000 @@ -21,6 +21,7 @@ #include "options.h" static const char cvsid[] = "$Id$"; +/* FIXME - this isn't right for all locales. Use glib's printf instead */ char * insert_commas (off_t number, char *dest_str, size_t dest_len) { @@ -87,31 +88,6 @@ } -long -file_countlf (int filefd, long endpos) -{ - char tempstr[255]; - long num, mypos; - ssize_t n; - int i; - - mypos = num = 0; - lseek (filefd, 0, SEEK_SET); - while ((n = read (filefd, tempstr, sizeof (tempstr))) > 0) - { - for (i = 0; i < n; i++) - { - if ((tempstr[i] == '\n') && (i > 0) && (tempstr[i - 1] != '\r') - && (endpos == 0 || mypos + i <= endpos)) - ++num; - } - mypos += n; - } - lseek (filefd, 0, SEEK_SET); - return (num); -} - - char * alltrim (char *str) { @@ -119,7 +95,7 @@ int diff; pos = str + strlen (str) - 1; - while (pos >= str && *pos == ' ') + while (pos >= str && (*pos == ' ' || *pos == '\t')) *pos-- = '\0'; pos = str; @@ -232,6 +208,7 @@ remove_double_slashes (char *string) { char *newpos, *oldpos; + size_t len; oldpos = newpos = string; while (*oldpos != '\0') @@ -243,8 +220,10 @@ oldpos++; } *newpos = '\0'; - if (string[strlen (string) - 1] == '/') - string[strlen (string) - 1] = '\0'; + + len = strlen (string); + if (string[len - 1] == '/') + string[len - 1] = '\0'; } @@ -294,13 +273,23 @@ exit (1); } - close (srcfd); - close (destfd); + if (close (srcfd) == -1) + { + printf (_("Error closing file descriptor: %s\n"), g_strerror (errno)); + exit (1); + } + + if (close (destfd) == -1) + { + printf (_("Error closing file descriptor: %s\n"), g_strerror (errno)); + exit (1); + } return (1); } +/* FIXME - is there a replacement for this */ int gftp_match_filespec (char *filename, char *filespec) { @@ -351,9 +340,11 @@ { if (*argc > 1) { - if (strcmp (argv[0][1], "--help") == 0 || strcmp (argv[0][1], "-h") == 0) + if (strcmp (argv[0][1], "--help") == 0 || + strcmp (argv[0][1], "-h") == 0) gftp_usage (); - else if (strcmp (argv[0][1], "--version") == 0 || strcmp (argv[0][1], "-v") == 0) + else if (strcmp (argv[0][1], "--version") == 0 || + strcmp (argv[0][1], "-v") == 0) { printf ("%s\n", version); exit (0); @@ -366,7 +357,7 @@ void gftp_usage (void) { - printf (_("usage: gftp [[ftp://][user:[pass]@]ftp-site[:port][/directory]]\n")); + printf (_("usage: gftp [[protocol://][user:[pass]@]site[:port][/directory]]\n")); exit (0); } @@ -394,9 +385,10 @@ g_free (exfile); if (!quit_on_err) return (NULL); + printf (_("gFTP Error: Cannot find file %s in %s or %s\n"), filename, SHARE_DIR, BASE_CONF_DIR); - exit (-1); + exit (1); } } } @@ -418,7 +410,7 @@ int i; ret = 0; - for (i=0; ((char *) key)[0] != '\0' && i < 3; i++) + for (i=0; ((char *) key)[i] != '\0' && i < 3; i++) ret += ((char *) key)[i]; return (ret); @@ -456,7 +448,7 @@ if (fle->destfile) g_free (fle->destfile); if (fle->fd > 0) - close (fle->fd); + close (fle->fd); /* FIXME - need to log a failure */ g_free (fle); } @@ -470,34 +462,20 @@ memcpy (newfle, fle, sizeof (*newfle)); if (fle->file) - { - newfle->file = g_malloc (strlen (fle->file) + 1); - strcpy (newfle->file, fle->file); - } + newfle->file = g_strdup (fle->file); if (fle->user) - { - newfle->user = g_malloc (strlen (fle->user) + 1); - strcpy (newfle->user, fle->user); - } + newfle->user = g_strdup (fle->user); if (fle->group) - { - newfle->group = g_malloc (strlen (fle->group) + 1); - strcpy (newfle->group, fle->group); - } + newfle->group = g_strdup (fle->group); if (fle->attribs) - { - newfle->attribs = g_malloc (strlen (fle->attribs) + 1); - strcpy (newfle->attribs, fle->attribs); - } + newfle->attribs = g_strdup (fle->attribs); if (fle->destfile) - { - newfle->destfile = g_malloc (strlen (fle->destfile) + 1); - strcpy (newfle->destfile, fle->destfile); - } + newfle->destfile = g_strdup (fle->destfile); + return (newfle); } @@ -510,7 +488,7 @@ int i, ret; ret = 1; - if (strcmp (request1->protocol_name, request2->protocol_name) == 0 && + if (request1->protonum == request2->protonum && request1->port == request2->port) { strarr[0][0] = request1->hostname; @@ -666,9 +644,9 @@ } return (-1); -#endif +#endif /* GRANTPT */ -#endif +#endif /* __sgi */ }