This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
blead is upstream for Math-BigInt-FastCalc
[perl5.git] / cpan / Sys-Syslog / Syslog.xs
CommitLineData
df6b13ce
AT
1#if defined(_WIN32)
2# include <windows.h>
3#endif
4
8ce86de8
GS
5#include "EXTERN.h"
6#include "perl.h"
7#include "XSUB.h"
1307ca85
JH
8#ifdef USE_PPPORT_H
9# include "ppport.h"
10#endif
8ce86de8 11
a650b841
AT
12#ifndef HAVE_SYSLOG
13#define HAVE_SYSLOG 1
14#endif
15
a650b841 16#if defined(_WIN32) && !defined(__CYGWIN__)
f93f88eb
AT
17# undef HAVE_SYSLOG
18# include "fallback/syslog.h"
19#else
20# if defined(I_SYSLOG) || PATCHLEVEL < 6
21# include <syslog.h>
22# endif
a650b841
AT
23#endif
24
89c3c464
AT
25static SV *ident_svptr;
26
1cb0fb50 27#include "const-c.inc"
8ce86de8 28
8ce86de8
GS
29MODULE = Sys::Syslog PACKAGE = Sys::Syslog
30
1cb0fb50 31INCLUDE: const-xs.inc
8ce86de8
GS
32
33int
34LOG_FAC(p)
35 INPUT:
36 int p
37 CODE:
38#ifdef LOG_FAC
39 RETVAL = LOG_FAC(p);
40#else
41 croak("Your vendor has not defined the Sys::Syslog macro LOG_FAC");
b621ec8a 42 RETVAL = -1;
8ce86de8
GS
43#endif
44 OUTPUT:
45 RETVAL
46
47int
48LOG_PRI(p)
49 INPUT:
50 int p
51 CODE:
52#ifdef LOG_PRI
53 RETVAL = LOG_PRI(p);
54#else
55 croak("Your vendor has not defined the Sys::Syslog macro LOG_PRI");
b621ec8a 56 RETVAL = -1;
8ce86de8
GS
57#endif
58 OUTPUT:
59 RETVAL
60
61int
62LOG_MAKEPRI(fac,pri)
63 INPUT:
64 int fac
65 int pri
66 CODE:
67#ifdef LOG_MAKEPRI
68 RETVAL = LOG_MAKEPRI(fac,pri);
69#else
70 croak("Your vendor has not defined the Sys::Syslog macro LOG_MAKEPRI");
b621ec8a 71 RETVAL = -1;
8ce86de8
GS
72#endif
73 OUTPUT:
74 RETVAL
75
76int
77LOG_MASK(pri)
78 INPUT:
79 int pri
80 CODE:
81#ifdef LOG_MASK
82 RETVAL = LOG_MASK(pri);
83#else
84 croak("Your vendor has not defined the Sys::Syslog macro LOG_MASK");
b621ec8a 85 RETVAL = -1;
8ce86de8
GS
86#endif
87 OUTPUT:
88 RETVAL
89
90int
91LOG_UPTO(pri)
92 INPUT:
93 int pri
94 CODE:
95#ifdef LOG_UPTO
96 RETVAL = LOG_UPTO(pri);
97#else
98 croak("Your vendor has not defined the Sys::Syslog macro LOG_UPTO");
b621ec8a 99 RETVAL = -1;
8ce86de8
GS
100#endif
101 OUTPUT:
102 RETVAL
89c3c464 103
a650b841 104#ifdef HAVE_SYSLOG
89c3c464
AT
105
106void
107openlog_xs(ident, option, facility)
108 INPUT:
109 SV* ident
110 int option
111 int facility
112 PREINIT:
113 STRLEN len;
114 char* ident_pv;
115 CODE:
116 ident_svptr = newSVsv(ident);
117 ident_pv = SvPV(ident_svptr, len);
118 openlog(ident_pv, option, facility);
119
120void
121syslog_xs(priority, message)
122 INPUT:
123 int priority
124 const char * message
125 CODE:
126 syslog(priority, "%s", message);
127
128int
129setlogmask_xs(mask)
130 INPUT:
131 int mask
132 CODE:
f93f88eb
AT
133 RETVAL = setlogmask(mask);
134 OUTPUT:
135 RETVAL
89c3c464
AT
136
137void
138closelog_xs()
139 CODE:
140 closelog();
141 if (SvREFCNT(ident_svptr))
142 SvREFCNT_dec(ident_svptr);
143
df6b13ce
AT
144#else /* HAVE_SYSLOG */
145
146void
147openlog_xs(ident, option, facility)
148 INPUT:
149 SV* ident
150 int option
151 int facility
152 CODE:
153
154void
155syslog_xs(priority, message)
156 INPUT:
157 int priority
158 const char * message
159 CODE:
160
161int
162setlogmask_xs(mask)
163 INPUT:
164 int mask
165 CODE:
166
167void
168closelog_xs()
169 CODE:
170
a650b841 171#endif /* HAVE_SYSLOG */