dvitomp fix from Akira
[mplib] / src / texk / kpathsea / string.c
1 /* libc replacement functions for win32.
2
3 Copyright (C) 1998, 99 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19 #ifdef __MINGW32__
20
21 #include <kpathsea/config.h>
22 #include <string.h>
23 #include <kpathsea/c-proto.h>
24 #include <kpathsea/win32lib.h>
25 #include <kpathsea/lib.h>
26
27 char *xstrdup(const char *s)
28 {
29   char *p = _strdup(s);
30   if (!p) {
31     fprintf(stderr, "strdup(%x) failed in gnuw32.c at line %d\n", s, __LINE__);
32     exit(1);
33   }
34   return p;
35 }
36
37 void *xmalloc(unsigned size)
38 {
39   void *p = malloc(size);
40   if (!p) {
41     fprintf(stderr, "malloc(%d) failed in gnuw32.c at line %d\n", size, __LINE__);
42     exit(1);
43   }
44   return p;
45 }
46
47 void *xrealloc(void *p, unsigned size)
48 {
49   p = realloc(p, size);
50   if (!p) {
51     fprintf(stderr, "realloc(%d) failed in gnuw32.c at line %d\n", size, __LINE__);
52     exit(1);
53   }
54   return p;
55 }
56
57 char *concat(const char *s1,  const char *s2)
58 {
59   char *answer = (char *) xmalloc (strlen (s1) + strlen (s2) + 1);
60   strcpy (answer, s1);
61   strcat (answer, s2);
62
63   return answer;
64 }
65
66 char *concat3(const char *s1,  const char *s2,  const char *s3)
67 {
68   char *answer
69     = (char *) xmalloc (strlen (s1) + strlen (s2) + strlen (s3) + 1);
70   strcpy (answer, s1);
71   strcat (answer, s2);
72   strcat (answer, s3);
73
74   return answer;
75 }
76
77 char *concatn(const char *str1,  ...)
78 {
79   char *arg, *ret;
80   int size = 1;
81   va_list marker;
82
83   if (!str1)
84     return NULL;
85
86   va_start(marker, str1);
87   while ((arg = va_arg (marker, char*)) != NULL) {
88     size += strlen(arg);
89   }
90   va_end (marker);
91   
92   
93   ret = xmalloc(size);
94   strcpy(ret, str1);
95   
96   va_start(marker, str1);
97   while ((arg = va_arg (marker, char*)) != NULL) {
98     strcat(ret, arg);
99   }
100   va_end (marker);
101   
102   return ret;
103 }
104
105 #endif