wined3d: Don't setup FBO and draw buffers in wined3d_context_gl_apply_blit_state().
[wine.git] / programs / winetest / util.c
blobbd5b584c3c4dfdbc3ce9b0926008ab0efc78440f
1 /*
2 * Utility functions.
4 * Copyright 2003 Dimitrie O. Paun
5 * Copyright 2003 Ferenc Wagner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
26 #include "winetest.h"
28 HANDLE logfile = 0;
30 void *xalloc (size_t len)
32 void *p = malloc( len );
34 if (!p) report (R_FATAL, "Out of memory.");
35 return p;
38 void *xrealloc (void *op, size_t len)
40 void *p = realloc(op, len);
42 if (len && !p) report (R_FATAL, "Out of memory.");
43 return p;
46 char *xstrdup( const char *str )
48 char* res = strdup( str );
49 if (!res) report (R_FATAL, "Out of memory.");
50 return res;
53 static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
55 size_t size = 1000;
56 char *p;
57 int n;
59 if (!fmt) fmt = "";
60 p = xalloc(size);
61 while (1) {
62 n = vsnprintf (p, size, fmt, ap);
63 if (n < 0) size *= 2; /* Windows */
64 else if ((unsigned)n >= size) size = n+1; /* glibc */
65 else break;
66 p = xrealloc(p, size);
68 if (lenp) *lenp = n;
69 return p;
72 char *vstrmake (size_t *lenp, va_list ap)
74 const char *fmt;
76 fmt = va_arg (ap, const char*);
77 return vstrfmtmake (lenp, fmt, ap);
80 char * WINAPIV strmake (size_t *lenp, ...)
82 va_list ap;
83 char *p;
85 va_start (ap, lenp);
86 p = vstrmake (lenp, ap);
87 va_end (ap);
88 return p;
91 void WINAPIV xprintf (const char *fmt, ...)
93 va_list ap;
94 size_t size;
95 DWORD written;
96 char *buffer, *head;
98 va_start (ap, fmt);
99 buffer = vstrfmtmake (&size, fmt, ap);
100 head = buffer;
101 va_end (ap);
102 while (size) {
103 if (!WriteFile( logfile, head, size, &written, NULL ))
104 report (R_FATAL, "Can't write logs: %u", GetLastError());
105 head += written;
106 size -= written;
108 free(buffer);
112 goodtagchar (char c)
114 return (('a'<=c && c<='z') ||
115 ('A'<=c && c<='Z') ||
116 ('0'<=c && c<='9') ||
117 c=='-' || c=='.');
120 const char *
121 findbadtagchar (const char *tag)
123 while (*tag)
124 if (goodtagchar (*tag)) tag++;
125 else return tag;
126 return NULL;