chiark / gitweb /
serialmgr: Look for things in /usr, not /usr/local
[sympathy.git] / src / util.c
index ea46e7727e9ee3f3f8cc0538c8f2eac328e7752a..7af8a1cb017ddbe73d1e58e8482f2ce0baf0c97b 100644 (file)
@@ -1,15 +1,30 @@
-/*
+/* 
  * util.c:
  *
- * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * Copyright (c) 2008 James McKenzie <sympathy@madingley.org>,
  * All rights reserved.
  *
  */
 
-static char rcsid[] = "$Id$";
+static char rcsid[] = "$Id: util.c,v 1.11 2008/03/07 14:13:40 james Exp $";
 
-/*
- * $Log$
+/* 
+ * $Log: util.c,v $
+ * Revision 1.11  2008/03/07 14:13:40  james
+ * *** empty log message ***
+ *
+ * Revision 1.10  2008/03/07 13:16:02  james
+ * *** empty log message ***
+ *
+ * Revision 1.9  2008/03/07 12:37:04  james
+ * *** empty log message ***
+ *
+ * Revision 1.8  2008/03/02 10:50:32  staffcvs
+ * *** empty log message ***
+ *
+ * Revision 1.7  2008/02/27 01:31:14  james
+ * *** empty log message ***
+ *
  * Revision 1.6  2008/02/27 00:54:16  james
  * *** empty log message ***
  *
@@ -38,8 +53,10 @@ wrap_read (int fd, void *buf, int len)
   int red;
 
   red = read (fd, buf, len);
+#if 0
   if (!red)
     return -1;
+#endif
 
   if ((red < 0) && (errno == EAGAIN))
     red = 0;
@@ -143,13 +160,50 @@ client_termios (struct termios *termios)
   cfsetospeed (termios, B9600);
 }
 
-int fput_cp(FILE *f,uint32_t ch)
+int
+fput_cp (FILE * f, uint32_t ch)
+{
+  char buf[4];
+  int i;
+  i = utf8_encode (buf, ch);
+
+  if (!i)
+    return 0;
+
+  return fwrite (buf, i, 1, f);
+}
+
+void
+crash_out (char *why)
+{
+  terminal_atexit ();
+  fprintf (stderr, "sympathy is aborting: %s\n", why ? why : "");
+  exit (1);
+}
+
+void *
+xmalloc (size_t s)
 {
-char buf[4];
-int i;
-i=utf8_encode(buf,ch);
+  void *ret = malloc (s);
+  if (!ret)
+    crash_out ("malloc failed");
+  return ret;
+}
 
-if (!i) return 0;
+void *
+xrealloc (void *p, size_t s)
+{
+  p = realloc (p, s);
+  if (!p)
+    crash_out ("realloc failed");
+  return p;
+}
 
-return fwrite(buf,i,1,f);
+char *
+xstrdup (const char *s)
+{
+  char *ret = strdup (s);
+  if (!ret)
+    crash_out ("strdup failed");
+  return ret;
 }