View | Details | Raw Unified | Return to issue 16425
Collapse All | Expand All

(-)checkdll/checkdll.c (-59 / +48 lines)
Lines 2-10 Link Here
2
 *
2
 *
3
 *  $RCSfile: checkdll.c,v $
3
 *  $RCSfile: checkdll.c,v $
4
 *
4
 *
5
 *  $Revision: 1.4 $
5
 *  $Revision: 1.3.8.1 $
6
 *
6
 *
7
 *  last change: $Author: mhu $ $Date: 2003/04/16 10:19:57 $
7
 *  last change: $Author: mh $ $Date: 2002/06/06 16:19:10 $
8
 *
8
 *
9
 *  The Contents of this file are made available subject to the terms of
9
 *  The Contents of this file are made available subject to the terms of
10
 *  either of the following licenses
10
 *  either of the following licenses
Lines 65-71 Link Here
65
#include <errno.h>
65
#include <errno.h>
66
#include <unistd.h>
66
#include <unistd.h>
67
#ifdef MACOSX
67
#ifdef MACOSX
68
#include <CoreFoundation/CoreFoundation.h>
68
#include <mach-o/dyld.h>
69
#else
69
#else
70
#include <dlfcn.h>
70
#include <dlfcn.h>
71
#endif
71
#endif
Lines 90-99 Link Here
90
{
90
{
91
	int 	rc;
91
	int 	rc;
92
#ifdef MACOSX
92
#ifdef MACOSX
93
    CFStringRef	    bundlePath;
93
        struct mach_header *pLib;
94
    CFURLRef        bundleURL;
95
    CFBundleRef     bundle;
96
    CFStringRef	    symbolName;
97
#else
94
#else
98
	void	*phandle;
95
	void	*phandle;
99
#endif
96
#endif
Lines 115-182 Link Here
115
112
116
#ifdef MACOSX
113
#ifdef MACOSX
117
114
118
    /* Convert char pointers to CFStringRefs */
115
        // Check if library is already loaded
119
    bundlePath = CFStringCreateWithCStringNoCopy(NULL, argv[1],
116
        pLib = NSAddImage(argv[1], NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED);
120
        CFStringGetSystemEncoding(), kCFAllocatorNull);
117
        if (!pLib) {
121
    symbolName = CFStringCreateWithCStringNoCopy(NULL, psymbol,
118
                // Check DYLD_LIBRARY_PATH
122
        CFStringGetSystemEncoding(), kCFAllocatorNull);
119
                pLib = NSAddImage(argv[1], NSADDIMAGE_OPTION_WITH_SEARCHING);
123
120
        }
124
    /* Get the framework's URL using its path */
121
        if (pLib) {
125
    if ((bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
122
                // Prefix symbol name with '_'
126
        bundlePath, kCFURLPOSIXPathStyle, true)) != NULL) {
123
                char *name = malloc(1+strlen(psymbol)+1);
127
	        /* Load the framework */
124
                NSSymbol *symbol;
128
            if ((bundle = CFBundleCreate( kCFAllocatorDefault,
125
                void *address = NULL;
129
                bundleURL)) != NULL) {
126
                strcpy(name, "_");
130
                    /* Load the shared library */
127
                strcat(name, psymbol);
131
                    if (CFBundleLoadExecutable(bundle)) {
128
                symbol = NSLookupSymbolInImage(pLib, name, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND);
132
                        if ((pfun = CFBundleGetFunctionPointerForName(bundle,
129
                free(name);
133
                            symbolName)) != NULL) {
130
                if (symbol) address = NSAddressOfSymbol(symbol);
134
	                            printf(": ok\n");
131
                if (address != NULL) {
135
                                CFRelease(bundlePath);
132
                        printf(": ok\n");
136
                                CFRelease(bundleURL);
133
#ifdef NO_UNLOAD_CHECK
137
                                CFRelease(bundle);
134
                        _exit(0);
138
                                CFRelease(symbolName);
135
#else
139
			                    return 0;
136
                        // Mac OS X can't unload dylibs
140
                        }
137
#endif
141
                        else
138
                        return 0;
142
	                        printf(": ERROR: symbol %s not found\n", psymbol);
139
                } else {
143
                    }
140
                        printf(": ERROR: symbol %s not found\n", psymbol);
144
                    /* No message printed since CFLog prints its own message */
141
                }
145
            }
142
        } else {
146
            else
143
                printf(": ERROR: %s is not a valid dylib name\n", argv[1]);
147
	            printf(": ERROR: %s is not a bundle\n", argv[1]);
144
        }
148
	}
149
    else
150
	    printf(": ERROR: %s is not a valid bundle name\n", argv[1]);
151
152
    CFRelease(bundlePath);
153
    if (bundleURL != NULL) CFRelease(bundleURL);
154
    if (bundle != NULL) CFRelease(bundle);
155
    CFRelease(symbolName);
156
	return 3;
145
	return 3;
157
146
147
        // fixme use NSLinkEditError() for better error messages
148
158
#else /* MACOSX */
149
#else /* MACOSX */
159
150
160
	if ( (phandle = dlopen(argv[1], RTLD_NOW)) != NULL )
151
	if ( (phandle = dlopen(argv[1], RTLD_NOW)) != NULL ) {
161
	{
152
		if  ( (pfun = (char *(*)(void))dlsym(phandle, psymbol)) != NULL ) {
162
		if  ( (pfun = (char *(*)(void))dlsym(phandle, psymbol)) != NULL )
163
		{
164
			printf(": ok\n");
153
			printf(": ok\n");
165
		}
166
		else
167
		{
168
			printf(": WARNING: %s\n", dlerror());
169
		}
170
171
#ifdef NO_UNLOAD_CHECK
154
#ifdef NO_UNLOAD_CHECK
172
		_exit(0);
155
			_exit(0);
173
#else
156
#else
174
		dlclose(phandle);
157
			dlclose(phandle);
175
#endif
158
#endif
176
		return 0;
159
			return 0;
160
		}
177
	}
161
	}
178
179
	printf(": ERROR: %s\n", dlerror());
162
	printf(": ERROR: %s\n", dlerror());
163
	if (phandle)
164
#ifdef NO_UNLOAD_CHECK
165
		_exit(3);
166
#else
167
		dlclose(phandle);
168
#endif
180
	return 3;
169
	return 3;
181
170
182
#endif /* MACOSX */
171
#endif /* MACOSX */
(-)checkdll/makefile.mk (+2 lines)
Lines 81-87 Link Here
81
APP1OBJS	=	$(OBJ)$/checkdll.obj
81
APP1OBJS	=	$(OBJ)$/checkdll.obj
82
DEPOBJFILES	=	$(APP1OBJS) 
82
DEPOBJFILES	=	$(APP1OBJS) 
83
.IF "$(OS)"!="FREEBSD"
83
.IF "$(OS)"!="FREEBSD"
84
.IF "$(OS)"!="MACOSX"
84
STDLIB += -ldl
85
STDLIB += -ldl
86
.ENDIF
85
.ENDIF
87
.ENDIF
86
.IF "$(OS)"=="NETBSD"
88
.IF "$(OS)"=="NETBSD"
87
APP1STDLIBS	+= -Wl,--whole-archive -lgcc -Wl,--no-whole-archive
89
APP1STDLIBS	+= -Wl,--whole-archive -lgcc -Wl,--no-whole-archive
(-)mkdepend/main.c (-10 / +26 lines)
Lines 27-33 Link Here
27
27
28
*/
28
*/
29
29
30
#if defined(FREEBSD)
30
#if defined(FREEBSD) || defined(MACOSX)
31
#include <sys/types.h>
31
#include <sys/types.h>
32
#include <sys/stat.h>
32
#include <sys/stat.h>
33
#endif
33
#endif
Lines 432-459 Link Here
432
	register int	fd;
432
	register int	fd;
433
	struct filepointer	*content;
433
	struct filepointer	*content;
434
	struct stat	st;
434
	struct stat	st;
435
	size_t size_backup;
435
	off_t		size_backup;
436
	ssize_t		bytes_read;
437
	size_t		malloc_size;
436
438
437
	content = (struct filepointer *)malloc(sizeof(struct filepointer));
439
	content = (struct filepointer *)malloc(sizeof(struct filepointer));
438
	if ((fd = open(file, O_RDONLY)) < 0) {
440
	if ((fd = open(file, O_RDONLY)) < 0) {
439
		warning("cannot open \"%s\"\n", file);
441
		warning("makedepend:  Cannot open file \"%s\"\n", file);
440
		content->f_p = content->f_base = content->f_end = (char *)malloc(1);
442
		content->f_p = content->f_base = content->f_end = (char *)malloc(1);
441
		*content->f_p = '\0';
443
		*content->f_p = '\0';
442
		return(content);
444
		return(content);
443
	}
445
	}
444
	fstat(fd, &st);
446
	fstat(fd, &st);
445
	content->f_base = (char *)malloc(st.st_size+1);
447
446
	if (content->f_base == NULL)
447
		fatalerr("cannot allocate mem\n");
448
	size_backup = st.st_size;
448
	size_backup = st.st_size;
449
	if ((st.st_size = read(fd, content->f_base, size_backup)) < 0)
449
	malloc_size = size_backup;
450
	/* Since off_t is larger than size_t, need to test for
451
	 * truncation.
452
	 */
453
	if ( malloc_size != size_backup )
454
	{
455
		close( fd );
456
		warning("makedepend:  File \"%s\" size larger than can fit in size_t.  Cannot allocate memory for contents.\n", file);
457
		content->f_p = content->f_base = content->f_end = (char *)malloc(1);
458
		*content->f_p = '\0';
459
		return(content);
460
	}
461
462
	content->f_base = (char *)malloc(malloc_size+1);
463
	if (content->f_base == NULL)
464
		fatalerr("makedepend:  Cannot allocate memory to process file \"%s\"\n", file);
465
	if ((bytes_read = read(fd, content->f_base, malloc_size)) < 0)
450
		if ( st.st_mode & S_IFREG )
466
		if ( st.st_mode & S_IFREG )
451
			fatalerr("failed to read %s\n", file);
467
			fatalerr("makedepend:  Failed to read file \"%s\"\n", file);
452
	
468
	
453
	close(fd);
469
	close(fd);
454
	content->f_len = st.st_size+1;
470
	content->f_len = bytes_read+1;
455
	content->f_p = content->f_base;
471
	content->f_p = content->f_base;
456
	content->f_end = content->f_base + st.st_size;
472
	content->f_end = content->f_base + bytes_read;
457
	*content->f_end = '\0';
473
	*content->f_end = '\0';
458
	content->f_line = 0;
474
	content->f_line = 0;
459
	return(content);
475
	return(content);

Return to issue 16425