Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / media / libjpeg / jinclude.h
blobe8d983ac171fa0e47c87f0e0593518ceddde0bdb
1 /*
2 * jinclude.h
4 * This file was part of the Independent JPEG Group's software:
5 * Copyright (C) 1991-1994, Thomas G. Lane.
6 * libjpeg-turbo Modifications:
7 * Copyright (C) 2022, D. R. Commander.
8 * For conditions of distribution and use, see the accompanying README.ijg
9 * file.
11 * This file exists to provide a single place to fix any problems with
12 * including the wrong system include files. (Common problems are taken
13 * care of by the standard jconfig symbols, but on really weird systems
14 * you may have to edit this file.)
16 * NOTE: this file is NOT intended to be included by applications using the
17 * JPEG library. Most applications need only include jpeglib.h.
20 #ifndef __JINCLUDE_H__
21 #define __JINCLUDE_H__
23 /* Include auto-config file to find out which system include files we need. */
25 #include "jconfig.h" /* auto configuration options */
26 #include "jconfigint.h"
27 #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
30 * Note that the core JPEG library does not require <stdio.h>;
31 * only the default error handler and data source/destination modules do.
32 * But we must pull it in because of the references to FILE in jpeglib.h.
33 * You can remove those references if you want to compile without <stdio.h>.
36 #include <stddef.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
42 * These macros/inline functions facilitate using Microsoft's "safe string"
43 * functions with Visual Studio builds without the need to scatter #ifdefs
44 * throughout the code base.
48 #ifdef _MSC_VER
50 #define SNPRINTF(str, n, format, ...) \
51 _snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
53 #else
55 #define SNPRINTF snprintf
57 #endif
60 #ifndef NO_GETENV
62 #ifdef _MSC_VER
64 static INLINE int GETENV_S(char *buffer, size_t buffer_size, const char *name)
66 size_t required_size;
68 return (int)getenv_s(&required_size, buffer, buffer_size, name);
71 #else /* _MSC_VER */
73 #include <errno.h>
75 /* This provides a similar interface to the Microsoft/C11 getenv_s() function,
76 * but other than parameter validation, it has no advantages over getenv().
79 static INLINE int GETENV_S(char *buffer, size_t buffer_size, const char *name)
81 char *env;
83 if (!buffer) {
84 if (buffer_size == 0)
85 return 0;
86 else
87 return (errno = EINVAL);
89 if (buffer_size == 0)
90 return (errno = EINVAL);
91 if (!name) {
92 *buffer = 0;
93 return 0;
96 env = getenv(name);
97 if (!env)
99 *buffer = 0;
100 return 0;
103 if (strlen(env) + 1 > buffer_size) {
104 *buffer = 0;
105 return ERANGE;
108 strncpy(buffer, env, buffer_size);
110 return 0;
113 #endif /* _MSC_VER */
115 #endif /* NO_GETENV */
118 #ifndef NO_PUTENV
120 #ifdef _WIN32
122 #define PUTENV_S(name, value) _putenv_s(name, value)
124 #else
126 /* This provides a similar interface to the Microsoft _putenv_s() function, but
127 * other than parameter validation, it has no advantages over setenv().
130 static INLINE int PUTENV_S(const char *name, const char *value)
132 if (!name || !value)
133 return (errno = EINVAL);
135 setenv(name, value, 1);
137 return errno;
140 #endif /* _WIN32 */
142 #endif /* NO_PUTENV */
145 #endif /* JINCLUDE_H */