xref: /haiku/src/libs/glut/glut_util.c (revision d3ff06683af390a4c2e83b69177e0a2eb76679bc)
1 
2 /* Copyright (c) Mark J. Kilgard, 1994. */
3 
4 /* This program is freely distributable without licensing fees
5    and is provided without guarantee or warrantee expressed or
6    implied. This program is -not- in the public domain. */
7 
8 #include <stdlib.h>
9 #include <stdarg.h>
10 #include <string.h>
11 #include <stdio.h>
12 
13 #include "glutint.h"
14 
15 /* strdup is actually not a standard ANSI C or POSIX routine
16    so implement a private one for GLUT.  OpenVMS does not have a
17    strdup; Linux's standard libc doesn't declare strdup by default
18    (unless BSD or SVID interfaces are requested). */
19 char *
20 __glutStrdup(const char *string)
21 {
22   char *copy;
23 
24   copy = (char*) malloc(strlen(string) + 1);
25   if (copy == NULL)
26     return NULL;
27   strcpy(copy, string);
28   return copy;
29 }
30 
31 void
32 __glutWarning(const char *format,...)
33 {
34   va_list args;
35 
36   va_start(args, format);
37   fprintf(stderr, "GLUT: Warning in %s: ",
38     __glutProgramName ? __glutProgramName : "(unamed)");
39   vfprintf(stderr, format, args);
40   va_end(args);
41   putc('\n', stderr);
42 }
43 
44 /* CENTRY */
45 void APIENTRY
46 glutReportErrors(void)
47 {
48   GLenum error;
49 
50   while ((error = glGetError()) != GL_NO_ERROR)
51     __glutWarning("GL error: %s", gluErrorString(error));
52 }
53 /* ENDCENTRY */
54 
55 void
56 __glutFatalError(const char *format,...)
57 {
58   va_list args;
59 
60   va_start(args, format);
61   fprintf(stderr, "GLUT: Fatal Error in %s: ",
62     __glutProgramName ? __glutProgramName : "(unamed)");
63   vfprintf(stderr, format, args);
64   va_end(args);
65   putc('\n', stderr);
66   exit(1);
67 }
68 
69 void
70 __glutFatalUsage(const char *format,...)
71 {
72   va_list args;
73 
74   va_start(args, format);
75   fprintf(stderr, "GLUT: Fatal API Usage in %s: ",
76     __glutProgramName ? __glutProgramName : "(unamed)");
77   vfprintf(stderr, format, args);
78   va_end(args);
79   putc('\n', stderr);
80   abort();
81 }
82