work/bootstrap/gec17.c
EIF_BOOLEAN eif_file_creatable(EIF_FILENAME path, EIF_INTEGER nbytes) {
	rt_stat_buf buf;			/* Buffer to get parent directory statistics */
	EIF_FILENAME temp = NULL;
	EIF_FILENAME ptr;
	size_t l_extra_bytes;

		/* Allocate one extra character, just to be sure since we might be appending characters. */
#ifdef EIF_WINDOWS
	l_extra_bytes = sizeof(wchar_t);
#else
	l_extra_bytes = sizeof(char);
#endif
	temp = (EIF_FILENAME) malloc (nbytes + l_extra_bytes);
	if (!temp) {
		enomem();
	} else {
			/* Search the directory separator. */
#ifdef EIF_WINDOWS
		memcpy (temp, path, nbytes);
		ptr = wcsrchr (temp, '\\');
		if (!ptr) {
				/* On Windows we can have a forward slash as separator. */
			ptr = wcsrchr (temp, '/');
		}
#else
		strcpy (temp, path);
		ptr = strrchr (temp, '/');
#endif
		if (ptr) {
			*ptr = '\0';
#ifdef EIF_WINDOWS
			if ((ptr == temp) || (*(ptr -1) == ':')) {
					/* path is of the form a:\bbb or \bbb, parent is a:\ or \ */
				wcscat (ptr, L"\\");
			}
#endif
		} else {
#ifdef EIF_WINDOWS
			wcsncpy (temp, L".", 2);
#else
			strcpy (temp, ".");
#endif
		}

			/* Does the parent exist? */
		if (!eif_file_exists(temp)) {
			free (temp);
			return (EIF_BOOLEAN) '\0';
		}

		rt_file_stat(temp, &buf);
		free (temp);

		if (S_ISDIR(buf.st_mode)) {	/* Is parent a directory? */
			if (eif_file_eaccess(&buf, 1)) {	/* Check for write permissions */
					/* Check if a non writable file `path' exists */
				if (eif_file_exists(path)) {
					rt_file_stat(path, &buf);
					if (S_ISDIR(buf.st_mode)) {
							/* File exists and it is already a directory, thus we cannot create a file. */
						return (EIF_BOOLEAN) '\0';
					} else {
						return (eif_file_eaccess(&buf, 1)); /* Check for write permissions to re create it */
					}
				}

				return (EIF_BOOLEAN) '\01';
			}
		}
	}
	return (EIF_BOOLEAN) '\0';
}
/*
 * Check whether the file `path' may be created: we need write permissions
 * in the parent directory and there must not be any file bearing that name
 * with no write permissions...
 */
Check whether the file `path' may be created: we need write permissions
in the parent directory and there must not be any file bearing that name
with no write permissions
Check whether the file ` path ' may be created : we need write permissions in the parent directory and there must not be any file bearing that name with no write permissions
EIF_BOOLEAN eif_file_creatable(EIF_FILENAME path, EIF_INTEGER nbytes) {
	rt_stat_buf buf;			
	EIF_FILENAME temp = NULL;
	EIF_FILENAME ptr;
	size_t l_extra_bytes;
#ifdef EIF_WINDOWS
	l_extra_bytes = sizeof(wchar_t);
#else
	l_extra_bytes = sizeof(char);
#endif
	temp = (EIF_FILENAME) malloc (nbytes + l_extra_bytes);
	if (!temp) {
		enomem();
	} else {
#ifdef EIF_WINDOWS
		memcpy (temp, path, nbytes);
		ptr = wcsrchr (temp, '\\');
		if (!ptr) {
			ptr = wcsrchr (temp, '/');
		}
#else
		strcpy (temp, path);
		ptr = strrchr (temp, '/');
#endif
		if (ptr) {
			*ptr = '\0';
#ifdef EIF_WINDOWS
			if ((ptr == temp) || (*(ptr -1) == ':')) {
				wcscat (ptr, L"\\");
			}
#endif
		} else {
#ifdef EIF_WINDOWS
			wcsncpy (temp, L".", 2);
#else
			strcpy (temp, ".");
#endif
		}
		if (!eif_file_exists(temp)) {
			free (temp);
			return (EIF_BOOLEAN) '\0';
		}
		rt_file_stat(temp, &buf);
		free (temp);
		if (S_ISDIR(buf.st_mode)) {	
			if (eif_file_eaccess(&buf, 1)) {	
				if (eif_file_exists(path)) {
					rt_file_stat(path, &buf);
					if (S_ISDIR(buf.st_mode)) {
						return (EIF_BOOLEAN) '\0';
					} else {
						return (eif_file_eaccess(&buf, 1)); 
					}
				}
				return (EIF_BOOLEAN) '\01';
			}
		}
	}
	return (EIF_BOOLEAN) '\0';
}
EIF_BOOLEAN eif_file_creatable ( EIF_FILENAME path , EIF_INTEGER nbytes ) { rt_stat_buf buf ; EIF_FILENAME temp = NULL ; EIF_FILENAME ptr ; size_t l_extra_bytes ; #ifdef EIF_WINDOWS l_extra_bytes = sizeof ( wchar_t ) ; #else l_extra_bytes = sizeof ( char ) ; #endif temp = ( EIF_FILENAME ) malloc ( nbytes + l_extra_bytes ) ; if ( ! temp ) { enomem ( ) ; } else { #ifdef EIF_WINDOWS memcpy ( temp , path , nbytes ) ; ptr = wcsrchr ( temp , ' \\ ' ) ; if ( ! ptr ) { ptr = wcsrchr ( temp , ' ' ) ; } #else strcpy ( temp , path ) ; ptr = strrchr ( temp , ' ' ) ; #endif if ( ptr ) { * ptr = ' \0 ' ; #ifdef EIF_WINDOWS if ( ( ptr == temp ) || ( * ( ptr - 1 ) == ' ' ) ) { wcscat ( ptr , L" \\ " ) ; } #endif } else { #ifdef EIF_WINDOWS wcsncpy ( temp , L" " , 2 ) ; #else strcpy ( temp , " " ) ; #endif } if ( ! eif_file_exists ( temp ) ) { free ( temp ) ; return ( EIF_BOOLEAN ) ' \0 ' ; } rt_file_stat ( temp , & buf ) ; free ( temp ) ; if ( S_ISDIR ( buf . st_mode ) ) { if ( eif_file_eaccess ( & buf , 1 ) ) { if ( eif_file_exists ( path ) ) { rt_file_stat ( path , & buf ) ; if ( S_ISDIR ( buf . st_mode ) ) { return ( EIF_BOOLEAN ) ' \0 ' ; } else { return ( eif_file_eaccess ( & buf , 1 ) ) ; } } return ( EIF_BOOLEAN ) ' \01 ' ; } } } return ( EIF_BOOLEAN ) ' \0 ' ; }
Check whether the file `path' may be created: we need write permissions
 in the parent directory and there must not be any file bearing that name
 with no write permissions...
Check whether the file ` path ' may be created : we need write permissions in the parent directory and there must not be any file bearing that name with no write permissions ...
/* Buffer to get parent directory statistics */ /* Allocate one extra character, just to be sure since we might be appending characters. */ /* Search the directory separator. */ /* On Windows we can have a forward slash as separator. */ /* path is of the form a:\bbb or \bbb, parent is a:\ or \ */ /* Does the parent exist? */ /* Is parent a directory? */ /* Check for write permissions */ /* Check if a non writable file `path' exists */ /* File exists and it is already a directory, thus we cannot create a file. */ /* Check for write permissions to re create it */