PUBLIC OSErr HCreate (INTEGER vref, LONGINT dirid, Str255 name, OSType creator, OSType type) { HParamBlockRec hpb; OSErr retval; hpb.fileParam.ioNamePtr = RM (name); hpb.fileParam.ioVRefNum = CW (vref); hpb.fileParam.ioDirID = CL (dirid); retval = PBHCreate (&hpb, FALSE); if (retval == noErr) { hpb.fileParam.ioFDirIndex = CWC (0); retval = PBHGetFInfo (&hpb, FALSE); if (retval == noErr) { hpb.fileParam.ioFlFndrInfo.fdCreator = CL (creator); hpb.fileParam.ioFlFndrInfo.fdType = CL (type); hpb.fileParam.ioDirID = CL (dirid); retval = PBHSetFInfo (&hpb, FALSE); } } return retval; }
/* * Algorithm for resolving an odbc.ini reference * * For UNIX : 1. Check for $ODBCINI variable, if exists return $ODBCINI. * 2. Check for $HOME/.odbc.ini or ~/.odbc.ini file, * if exists return it. * 3. Check for SYS_ODBC_INI build variable, if exists return * it. (ie : /etc/odbc.ini). * 4. No odbc.ini presence, return NULL. * * For WINDOWS, WIN32, OS2 : * 1. Check for the system odbc.ini file, if exists return it. * 2. No odbc.ini presence, return NULL. * * For VMS: 1. Check for $ODBCINI variable, if exists return $ODBCINI. * 2. Check for SYS$LOGIN:ODBC.INI file, if exists return it. * 3. No odbc.ini presence, return NULL. * * For Mac: 1. On powerPC, file is ODBC Preferences PPC * On 68k, file is ODBC Preferences * 2. Check for ...:System Folder:Preferences:ODBC Preferences * file, if exists return it. * 3. No odbc.ini presence, return NULL. * * For MacX: 1. Check for $ODBCINI variable, if exists return $ODBCINI. * 2. Check for $HOME/.odbc.ini or ~/.odbc.ini file, if exists * return it. * 3. Check for $HOME/Library/ODBC/odbc.ini or * ~/.odbc.ini file, if exists return it. * 4. Check for SYS_ODBC_INI build variable, if exists return * it. (ie : /etc/odbc.ini). * 5. Check for /Library/ODBC/odbc.ini * file, if exists return it. * 6. No odbc.ini presence, return NULL. */ char * _iodbcadm_getinifile (char *buf, int size, int bIsInst, int doCreate) { #ifdef _MAC HParamBlockRec hp; long fldrDid; short fldrRef; OSErr result; #endif /* endif _MAC */ int i, j; char *ptr; #ifdef _MAC # ifdef __POWERPC__ j = STRLEN (bIsInst ? ":ODBC Installer Preferences PPC" : ":ODBC Preferences PPC") + 1; # else j = STRLEN (bIsInst ? ":ODBC Installer Preferences" : ":ODBC Preferences") + 1; # endif /* endif __POWERPC__ */ #else j = STRLEN (bIsInst ? "/odbcinst.ini" : "/odbc.ini") + 1; #endif /* endif _MAC */ if (size < j) return NULL; #if !defined(UNIX_PWD) # ifdef _MAC result = FindFolder (kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &fldrRef, &fldrDid); if (result != noErr) return NULL; ptr = get_full_pathname (fldrDid, fldrRef); i = (ptr) ? STRLEN (ptr) : 0; if (i == 0 || i > size - j) { if (ptr) free (ptr); return NULL; } # ifdef __POWERPC__ STRCPY (buf, ptr); STRCAT (buf, bIsInst ? ":ODBC Installer Preferences PPC" : ":ODBC Preferences PPC"); # else STRCPY (buf, ptr); STRCAT (buf, bIsInst ? ":ODBC Installer Preferences" : ":ODBC Preferences"); # endif /* endif __POWERPC__ */ if (doCreate) { hp.fileParam.ioCompletion = NULL; hp.fileParam.ioVRefNum = fldrRef; hp.fileParam.ioDirID = fldrDid; # ifdef __POWERPC__ hp.fileParam.ioNamePtr = bIsInst ? "\pODBC Installer Preferences PPC" : "\pODBC Preferences PPC"; # else hp.fileParam.ioNamePtr = bIsInst ? "\pODBC Installer Preferences" : "\pODBC Preferences"; # endif PBHCreate (&hp, FALSE); } free (ptr); return buf; # else /* else _MAC */ /* * On Windows, there is only one place to look */ i = GetWindowsDirectory ((LPSTR) buf, size); if (i == 0 || i > size - j) return NULL; snprintf (buf + i, size - i, bIsInst ? "/odbcinst.ini" : "/odbc.ini"); return buf; # endif /* endif _MAC */ #else if (wSystemDSN == USERDSN_ONLY) { /* * 1. Check $ODBCINI environment variable */ if ((ptr = getenv (bIsInst ? "ODBCINSTINI" : "ODBCINI")) != NULL) { STRNCPY (buf, ptr, size); if (access (buf, R_OK) == 0) return buf; else if (doCreate) { int f = open ((char *) buf, O_CREAT, S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (f != -1) { close (f); return buf; } } } # ifdef VMS /* * 2a. VMS calls this HOME */ STRNCPY (buf, bIsInst ? "SYS$LOGIN:ODBCINST.INI" : "SYS$LOGIN:ODBC.INI", size); if (doCreate || access (buf, R_OK) == 0) return buf; # else /* else VMS */ /* * 2b. Check either $HOME/.odbc.ini or ~/.odbc.ini */ if ((ptr = getenv ("HOME")) == NULL) { ptr = (char *) getpwuid (getuid ()); if (ptr != NULL) ptr = ((struct passwd *) ptr)->pw_dir; } if (ptr != NULL) { snprintf (buf, size, bIsInst ? "%s/.odbcinst.ini" : "%s/.odbc.ini", ptr); if (doCreate || access (buf, R_OK) == 0) return buf; #if defined(__APPLE__) /* * Try to check the ~/Library/ODBC/odbc.ini */ snprintf (buf, size, bIsInst ? "%s" ODBCINST_INI_APP : "%s" ODBC_INI_APP, ptr); if (access (buf, R_OK) == 0) return buf; else if (doCreate) { int f = open ((char *) buf, O_CREAT, S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (f != -1) { close (f); return buf; } } # endif /* endif __APPLE__ */ } # endif /* endif VMS */ } /* * 3. Try SYS_ODBC_INI as the last resort */ if (wSystemDSN == SYSTEMDSN_ONLY || bIsInst) { /* * 1. Check $SYSODBCINI environment variable */ if ((ptr = getenv (bIsInst ? "SYSODBCINSTINI" : "SYSODBCINI")) != NULL) { STRNCPY (buf, ptr, size); if (access (buf, R_OK) == 0) return buf; else if (doCreate) { int f = open ((char *) buf, O_CREAT, S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (f != -1) { close (f); return buf; } } } #if defined(__APPLE__) /* * Try to check the /Library/ODBC/odbc.ini */ snprintf (buf, size, "%s", bIsInst ? ODBCINST_INI_APP : ODBC_INI_APP); if (access (buf, R_OK) == 0) return buf; else if (doCreate) { int f = open ((char *) buf, O_CREAT, S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (f != -1) { close (f); return buf; } } # endif /* endif __APPLE__ */ STRNCPY (buf, bIsInst ? SYS_ODBCINST_INI : SYS_ODBC_INI, size); return buf; } /* * No ini file found or accessible */ return NULL; #endif /* UNIX_PWD */ }