1 /* Copyright (C) 1992, 1993, 1994, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: gp_win32.c,v 1.5 2002/10/07 08:28:56 ghostgum Exp $ */
18 /* Common platform-specific routines for MS-Windows WIN32 */
19 /* originally hacked from gp_msdos.c by Russell Lang */
20 #include "malloc_.h"
21 #include "stdio_.h"
22 #include "string_.h" /* for strerror */
23 #include "gstypes.h"
24 #include "gsmemory.h" /* for gp.h */
25 #include "gserror.h"
26 #include "gserrors.h"
27 #include "gp.h"
28 #include "windows_.h"
29
30 /* ------ Miscellaneous ------ */
31
32 /* Get the string corresponding to an OS error number. */
33 /* This is compiler-, not OS-, specific, but it is ANSI-standard and */
34 /* all MS-DOS and MS Windows compilers support it. */
35 const char *
gp_strerror(int errnum)36 gp_strerror(int errnum)
37 {
38 return strerror(errnum);
39 }
40
41 /* ------ Date and time ------ */
42
43 /* Read the current time (in seconds since Jan. 1, 1980) */
44 /* and fraction (in nanoseconds). */
45 void
gp_get_realtime(long * pdt)46 gp_get_realtime(long *pdt)
47 {
48 SYSTEMTIME st;
49 long idate;
50 static const int mstart[12] = {
51 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
52 };
53
54 /* This gets UTC, not local time */
55 /* We have no way of knowing the time zone correction */
56 GetSystemTime(&st);
57 idate = (st.wYear - 1980) * 365 + /* days per year */
58 ((st.wYear - 1) / 4 - 1979 / 4) + /* intervening leap days */
59 (1979 / 100 - (st.wYear - 1) / 100) +
60 ((st.wYear - 1) / 400 - 1979 / 400) +
61 mstart[st.wMonth - 1] + /* month is 1-origin */
62 st.wDay - 1; /* day of month is 1-origin */
63 idate += (2 < st.wMonth
64 && (st.wYear % 4 == 0
65 && (st.wYear % 100 != 0 || st.wYear % 400 == 0)));
66 pdt[0] = ((idate * 24 + st.wHour) * 60 + st.wMinute) * 60 + st.wSecond;
67 pdt[1] = st.wMilliseconds * 1000000;
68 }
69
70 /* Read the current user CPU time (in seconds) */
71 /* and fraction (in nanoseconds). */
72 void
gp_get_usertime(long * pdt)73 gp_get_usertime(long *pdt)
74 {
75 gp_get_realtime(pdt); /* Use an approximation for now. */
76 }
77
78 /* ------ Console management ------ */
79
80 /* Answer whether a given file is the console (input or output). */
81 /* This is not a standard gp procedure, */
82 /* but the MS Windows configuration needs it, */
83 /* and other MS-DOS configurations might need it someday. */
84 int
gp_file_is_console(FILE * f)85 gp_file_is_console(FILE * f)
86 {
87 #ifdef __DLL__
88 if (f == NULL)
89 return 1;
90 #else
91 if (f == NULL)
92 return 0;
93 #endif
94 if (fileno(f) <= 2)
95 return 1;
96 return 0;
97 }
98
99 /* ------ Screen management ------ */
100
101 /* Get the environment variable that specifies the display to use. */
102 const char *
gp_getenv_display(void)103 gp_getenv_display(void)
104 {
105 return NULL;
106 }
107
108 /* ------ File names ------ */
109
110 /* Define the default scratch file name prefix. */
111 const char gp_scratch_file_name_prefix[] = "_temp_";
112
113 /* Define the name of the null output file. */
114 const char gp_null_file_name[] = "nul";
115
116 /* Define the name that designates the current directory. */
117 const char gp_current_directory_name[] = ".";
118