]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/crt-old-mac10.5-vars-libSystem.dtest/main.c
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / crt-old-mac10.5-vars-libSystem.dtest / main.c
1 // BUILD_ONLY: MacOSX
2 // BUILD_MIN_OS: 10.5
3
4 // BUILD: $CC main.c -o $BUILD_DIR/crt-vars10.5-libSystem.exe
5
6 // RUN: ./crt-vars10.5-libSystem.exe
7
8 #include <stdio.h>
9 #include <dlfcn.h>
10 #include <string.h>
11 #include <crt_externs.h>
12 #include <mach-o/ldsyms.h>
13
14 #include "test_support.h"
15
16 // This struct is passed as fifth parameter to libSystem.dylib's initializer so it record
17 // the address of crt global variables.
18 struct ProgramVars
19 {
20 const void* mh;
21 int* NXArgcPtr;
22 char*** NXArgvPtr;
23 char*** environPtr;
24 char** __prognamePtr;
25 };
26
27
28 // global variables defeined in crt1.o
29 extern char** NXArgv;
30 extern int NXArgc;
31 extern char** environ;
32 extern char* __progname;
33
34
35 static const struct ProgramVars* sVars;
36
37 void __attribute__((constructor))
38 myInit(int argc, const char* argv[], const char* envp[], const char* apple[], const struct ProgramVars* vars)
39 {
40 sVars = vars;
41 }
42
43
44 int main(int argc, const char* argv[])
45 {
46 if ( _NSGetArgv() != &NXArgv ) {
47 FAIL("crt-libSystem: _NSGetArgv() != &NXArgv (%p!=%p) for %s", _NSGetArgv(), &NXArgv, argv[0]);
48 }
49
50 if ( _NSGetArgc() != &NXArgc ) {
51 FAIL("crt-libSystem: _NSGetArgc() != &NXArgc (%p!=%p) for %s", _NSGetArgc(), &NXArgc, argv[0]);
52 }
53
54 if ( _NSGetEnviron() != &environ ) {
55 FAIL("crt-libSystem: _NSGetEnviron() != &environv (%p!=%p) for %s", _NSGetEnviron(), &environ, argv[0]);
56 }
57
58 if ( _NSGetProgname() != &__progname ) {
59 FAIL("crt-libSystem: _NSGetProgname() != &__progname (%p!=%p) for %s", _NSGetProgname(), &__progname, argv[0]);
60 }
61
62 if ( _NSGetMachExecuteHeader() != &_mh_execute_header ) {
63 FAIL("crt-libSystem: _NSGetMachExecuteHeader() != &_mh_execute_headerv (%p!=%p) for %s", _NSGetMachExecuteHeader(), &_mh_execute_header, argv[0]);
64 }
65
66 if ( sVars->NXArgvPtr != &NXArgv ) {
67 FAIL("crt-libSystem: sVars->NXArgvPtr != &NXArg (%p!=%p) for %s", sVars->NXArgvPtr, &NXArgv, argv[0]);
68 }
69
70 if ( sVars->NXArgcPtr != &NXArgc ) {
71 FAIL("crt-libSystem: sVars->NXArgcPtr != &NXArgc (%p!=%p) for %s", sVars->NXArgcPtr, &NXArgc, argv[0]);
72 }
73
74 if ( sVars->environPtr != &environ ) {
75 FAIL("crt-libSystem: sVars->environPtr != &environ (%p!=%p) for %s", sVars->environPtr, &environ, argv[0]);
76 }
77
78 if ( sVars->__prognamePtr != &__progname ) {
79 FAIL("crt-libSystem: sVars->__prognamePtr != &__progname (%p!=%p) for %s", sVars->__prognamePtr, &__progname, argv[0]);
80 }
81
82 if ( sVars->mh != &_mh_execute_header ) {
83 FAIL("crt-libSystem: sVars->mh != &_mh_execute_header (%p!=%p) for %s", sVars->mh, &_mh_execute_header, argv[0]);
84 }
85
86 PASS("Success");
87 }
88