]> git.vpit.fr Git - perl/modules/Mac-NSGetExecutablePath.git/blob - NSGetExecutablePath.xs
This is 0.01
[perl/modules/Mac-NSGetExecutablePath.git] / NSGetExecutablePath.xs
1 /* This file is part of the Mac::NSGetExecutablePath Perl module.
2  * See http://search.cpan.org/dist/Mac-NSGetExecutablePath/ */
3
4 #define PERL_NO_GET_CONTEXT
5 #include "EXTERN.h"
6 #include "perl.h"
7 #include "XSUB.h"
8
9 #include <mach-o/dyld.h>
10
11
12 static const char nsgep_too_long[] = "NSGetExecutablePath() wants to return a path too large";
13
14 /* --- XS ------------------------------------------------------------------ */
15
16 MODULE = Mac::NSGetExecutablePath        PACKAGE = Mac::NSGetExecutablePath
17
18 PROTOTYPES: ENABLE
19
20 void
21 NSGetExecutablePath()
22 PROTOTYPE:
23 PREINIT:
24  char      buf[1];
25  uint32_t  size = sizeof buf;
26  SV       *dst;
27  char     *buffer;
28 PPCODE:
29  _NSGetExecutablePath(buf, &size);
30  if (size >= MAXPATHLEN * MAXPATHLEN)
31   croak(nsgep_too_long);
32 #ifdef newSV_type
33  dst = newSV_type(SVt_PV);
34 #else
35  dst = sv_newmortal();
36  (void) SvUPGRADE(dst, SVt_PV);
37 #endif
38  buffer = SvGROW(dst, size);
39  if (_NSGetExecutablePath(buffer, &size))
40   croak(nsgep_too_long);
41  SvCUR_set(dst, size - 1);
42  SvPOK_on(dst);
43  XPUSHs(dst);
44  XSRETURN(1);