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). */
19char *
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
31void
32__glutWarning(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 */
45void GLUTAPIENTRY
46glutReportErrors(void)
47{
48  GLenum error;
49
50  while ((error = glGetError()) != GL_NO_ERROR)
51    __glutWarning("GL error: %s", gluErrorString(error));
52}
53/* ENDCENTRY */
54
55void
56__glutFatalError(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#ifdef _WIN32
67  if (__glutExitFunc) {
68    __glutExitFunc(1);
69  }
70#endif
71  exit(1);
72}
73
74void
75__glutFatalUsage(char *format,...)
76{
77  va_list args;
78
79  va_start(args, format);
80  fprintf(stderr, "GLUT: Fatal API Usage in %s: ",
81    __glutProgramName ? __glutProgramName : "(unamed)");
82  vfprintf(stderr, format, args);
83  va_end(args);
84  putc('\n', stderr);
85  abort();
86}
87