/* * File to be installed as /usr/bin/python to support my * Python multi-lib / multi-arch . * */ #include #include #include #include #include #undef putenv extern int putenv(char *string); extern char **environ; int main(int argc, char **argv, char **envp) { char **new_argv = (void*)malloc( (argc+1) * sizeof(void*)); int i, len; struct utsname uts; char *pycmd=malloc((len = strlen(argv[0]))+256), *pybin=strrchr(argv[0],'/'), *python = 0L, *pyver = 0L, *pyhome = strdup("PYTHONHOME= "); if( pybin ) { strcpy( pycmd, argv[0]); if( pybin ) { ++pybin; python = (void*)(((unsigned long)pycmd)+(((unsigned long)pybin)-((unsigned long)argv[0]))); }else { python = pycmd; } }else { pybin = argv[0]; strcpy(pycmd,"/usr/bin/"); python=&pycmd[9]; } if( (pybin[5] == 'n') && (pybin[6] == '\0' ) ) { pyver="2.7.1"; }else { if( (pybin[6] == '2') && (pybin[7]=='\0')) { pybin[6] = '\0'; pyver="2.7.1"; }else pyver = &pybin[6]; } for(i=1; i <= argc; i++) { new_argv[i] = argv[i]; } if( ( uname( &uts ) == 0 ) &&( ( /* ix86 : */ ( uts.machine[0] == 'i') && (uts.machine[1] >= '3') && (uts.machine[1] <= '6') && (uts.machine[2] == '8') && (uts.machine[3] == '6') && (uts.machine[4] == '\0') ) || ( /* x86 : */ ( uts.machine[0] == 'x' ) && ( uts.machine[1] == '8' ) && ( uts.machine[2] == '6' ) && ( uts.machine[3] == '\0') ) ) ) { strcpy(python, "/32/"); python += 4; strcpy(python, pybin ); strcpy(&pyhome[11],"/usr/lib32/python"); strcat(&pyhome[11],pyver); }else { strcpy(python, pybin ); if( pyver != &pybin[6] ) strcat(pycmd, pyver); strcat(pycmd, ".bin"); strcpy(&pyhome[11],"/usr/lib64/python"); strcat(&pyhome[11],pyver); } new_argv[0] = pycmd; putenv(pyhome); execve( new_argv[0], new_argv, environ ); }