Skip to content

Commit 63836f7

Browse files
committed
fix build on OmniOS/Solaris
1 - OmniOS doesn't have vdprintf(), use fdopen()+vfprintf() to workaround this problem; 2 - Remove the _XOPEN_SOURCE definition in src/user_types/user_date_and_time.c to fix this compiler error: "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications". This change doesn't affect libyang build on Debian 9.3 and OpenBSD 6.3. Signed-off-by: Renato Westphal <[email protected]>
1 parent 11edb00 commit 63836f7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
22
project(libyang C)
33

44
include(GNUInstallDirs)
5+
include(CheckSymbolExists)
56

67
set(LIBYANG_DESCRIPTION "libyang is YANG data modelling language parser and toolkit written (and providing API) in C.")
78

@@ -232,6 +233,11 @@ set(headers
232233
src/xml.h
233234
src/dict.h)
234235

236+
check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF)
237+
if(HAVE_VDPRINTF)
238+
add_definitions(-DHAVE_VDPRINTF)
239+
endif(HAVE_VDPRINTF)
240+
235241
# create static libyang library
236242
if(ENABLE_STATIC)
237243
add_definitions(-DSTATIC)

src/printer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,23 @@ ly_print(struct lyout *out, const char *format, ...)
7979
int count = 0;
8080
char *msg = NULL, *aux;
8181
va_list ap;
82+
#ifndef HAVE_VDPRINTF
83+
FILE *stream;
84+
#endif
8285

8386
va_start(ap, format);
8487

8588
switch(out->type) {
8689
case LYOUT_FD:
90+
#ifdef HAVE_VDPRINTF
8791
count = vdprintf(out->method.fd, format, ap);
92+
#else
93+
stream = fdopen(dup(out->method.fd), "a+");
94+
if (stream) {
95+
count = vfprintf(stream, format, ap);
96+
fclose(stream);
97+
}
98+
#endif
8899
break;
89100
case LYOUT_STREAM:
90101
count = vfprintf(out->method.f, format, ap);

src/user_types/user_date_and_time.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*
1212
* https://opensource.org/licenses/BSD-3-Clause
1313
*/
14-
#define _XOPEN_SOURCE
1514
#define _GNU_SOURCE
1615

1716
#include <stdlib.h>

0 commit comments

Comments
 (0)