diff lib/misc.c @ 125:b875de05c22d

2003-4-8 Brian Masney <masneyb@gftp.org> * src/text/gftp-text.c lib/misc.c - moved r_gethostbyname() and r_getservbyname() to lib/misc.c. Now uses GMutex functions * lib/config_file.c lib/gftp.h lib/options.h - added config variable type textcombo. default_protocol uses this * lib/config_file.c (gftp_read_config_file) - when reading in the list of supported protocols, add the protocol names to the list associated with default_protocol. Also, don't try to have default_protocol fall back to FTP. The code that uses this will fall back properly * lib/gftp.h (struct gftp_transfer) - renamed node to user_data * lib/misc.c lib/gftp.h - moved parse_attribs() from src/gtk/transfer.c to misc.c. Renamed to gftp_parse_attribs() * lib/protocols.c lib/gftp.h - moved get_status() from src/gtk/transfer.c to protocols.c. Renamed to gftp_get_transfer_status(). Uses GMutex functions
author masneyb
date Tue, 08 Apr 2003 22:28:17 +0000
parents 65048c959029
children fe0b21c006f6
line wrap: on
line diff
--- a/lib/misc.c	Tue Apr 08 01:43:33 2003 +0000
+++ b/lib/misc.c	Tue Apr 08 22:28:17 2003 +0000
@@ -933,3 +933,100 @@
   return (filelist);
 }
 
+
+mode_t
+gftp_parse_attribs (char *attribs)
+{
+  mode_t mode;
+  int cur;
+
+  cur = 0;
+  if (attribs[1] == 'r')
+    cur += 4;
+  if (attribs[2] == 'w')
+    cur += 2;
+  if (attribs[3] == 'x' ||
+      attribs[3] == 's')
+    cur += 1;
+  mode = cur;
+
+  cur = 0;
+  if (attribs[4] == 'r')
+    cur += 4;
+  if (attribs[5] == 'w')
+    cur += 2;
+  if (attribs[6] == 'x' ||
+      attribs[6] == 's')
+    cur += 1;
+  mode = (mode * 10) + cur;
+
+  cur = 0;
+  if (attribs[7] == 'r')
+    cur += 4;
+  if (attribs[8] == 'w')
+    cur += 2;
+  if (attribs[9] == 'x' ||
+      attribs[9] == 's')
+    cur += 1;
+  mode = (mode * 10) + cur;
+
+  return (mode);
+}
+
+
+#if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR)
+
+struct hostent *
+r_gethostbyname (const char *name, struct hostent *result_buf, int *h_errnop)
+{
+  static GStaticMutex hostfunclock = G_STATIC_MUTEX_INIT; 
+  struct hostent *hent;
+
+  if (g_thread_supported ())
+    g_static_mutex_lock (&hostfunclock);
+
+  if ((hent = gethostbyname (name)) == NULL)
+    {
+      if (h_errnop)
+        *h_errnop = h_errno;
+    }
+  else
+    {
+      *result_buf = *hent;
+      hent = result_buf;
+    }
+
+  if (g_thread_supported ())
+    g_static_mutex_unlock (&hostfunclock);
+
+  return (hent);
+}
+
+#endif /* !HAVE_GETADDRINFO */
+
+struct servent *
+r_getservbyname (const char *name, const char *proto,
+                 struct servent *result_buf, int *h_errnop)
+{
+  static GStaticMutex servfunclock = G_STATIC_MUTEX_INIT;
+  struct servent *sent;
+
+  if (g_thread_supported ())
+    g_static_mutex_lock (&servfunclock);
+
+  if ((sent = getservbyname (name, proto)) == NULL)
+    {
+      if (h_errnop)
+        *h_errnop = h_errno;
+    }
+  else
+    {
+      *result_buf = *sent;
+      sent = result_buf;
+    }
+
+  if (g_thread_supported ())
+    g_static_mutex_unlock (&servfunclock);
+  return (sent);
+}
+