]> git.vpit.fr Git - perl/modules/Mac-NSGetExecutablePath.git/blob - NSGetExecutablePath.xs
Update VPIT::TestHelpers to 15e8aee3
[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 static const char nsgep_too_long[] = "NSGetExecutablePath() wants to return a path too large";
12
13 /* --- XS ------------------------------------------------------------------ */
14
15 MODULE = Mac::NSGetExecutablePath        PACKAGE = Mac::NSGetExecutablePath
16
17 PROTOTYPES: ENABLE
18
19 void
20 NSGetExecutablePath()
21 PROTOTYPE:
22 PREINIT:
23  char      buf[1];
24  uint32_t  size = sizeof buf;
25  SV       *dst;
26  char     *buffer;
27 PPCODE:
28  _NSGetExecutablePath(buf, &size);
29  if (size >= MAXPATHLEN * MAXPATHLEN)
30   croak(nsgep_too_long);
31  dst    = sv_newmortal();
32  sv_upgrade(dst, SVt_PV);
33  buffer = SvGROW(dst, size);
34  if (_NSGetExecutablePath(buffer, &size))
35   croak(nsgep_too_long);
36  if (size)
37   SvCUR_set(dst, size - 1);
38  SvPOK_on(dst);
39  XPUSHs(dst);
40  XSRETURN(1);