libbfio: FTBFS on hurd-i386 (for review)
Source: libbfio
Version: 20130507-1
Severity: important
Tags: patch
User: debian-hurd@lists.debian.org
Usertags: hurd
Hi,
Currently libbfio fails to build from source due to a usage of PATH_MAX,
which is not defined on GNU/Hurd. The attached patch solved this problem
by using getcwd (NULL, 0) to allocate space in file
libcpath/libcpath_path.c as specified by POSIX.1-2001.
Thanks!
To debian-hurd:
Questions:
- is only getcwd(NULL, size), size != 0 specified by POSIX?
- if so, should I add a configure.ac test?
Comments:
- save for formatting errors
- to be tested with Valgrind on Linux
- I would prefer to remove the PATH_MAX code path if possible -> upstream?
Index: libbfio-20130507/libcpath/libcpath_path.c
===================================================================
--- libbfio-20130507.orig/libcpath/libcpath_path.c
+++ libbfio-20130507/libcpath/libcpath_path.c
@@ -356,9 +356,27 @@ int libcpath_path_get_current_working_di
}
#if defined( WINAPI )
*current_working_directory_size = (size_t) _MAX_PATH;
+#endif
+
+#if (_POSIX_C_SOURCE - 0) >= 200112L && !defined( WINAPI )
+ *current_working_directory_size = 0;
+ *current_working_directory = getcwd(NULL,0);
+
+ if ( *current_working_directory == NULL )
+ {
+ libcerror_system_set_error(
+ error,
+ LIBCERROR_ERROR_DOMAIN_RUNTIME,
+ LIBCERROR_RUNTIME_ERROR_GET_FAILED,
+ errno,
+ "%s: unable to retrieve current working directory.",
+ function );
+
+ goto on_error;
+ }
+ *current_working_directory_size = strlen(*current_working_directory) + 1;
#else
*current_working_directory_size = (size_t) PATH_MAX;
-#endif
*current_working_directory = libcstring_narrow_string_allocate(
*current_working_directory_size );
@@ -387,6 +405,8 @@ int libcpath_path_get_current_working_di
goto on_error;
}
+#endif /* (_POSIX_C_SOURCE - 0) >= 200112L && !defined( WINAPI ) */
+#if !((_POSIX_C_SOURCE - 0) >= 200112L)
#if defined( WINAPI )
if( _getcwd(
*current_working_directory,
@@ -417,7 +437,9 @@ int libcpath_path_get_current_working_di
goto on_error;
}
-#endif
+#endif /* defined( WINAPI ) */
+#endif /* !((_POSIX_C_SOURCE - 0) >= 200112L) */
+
return( 1 );
on_error:
@@ -3113,6 +3135,20 @@ int libcpath_path_get_current_working_di
#if defined( WINAPI )
*current_working_directory_size = (size_t) _MAX_PATH;
#else
+#if (_POSIX_C_SOURCE - 0) >= 200112L
+ narrow_current_working_directory = getcwd(NULL, 0);
+ if( narrow_current_working_directory == NULL )
+ {
+ libcerror_error_set(
+ error,
+ LIBCERROR_ERROR_DOMAIN_MEMORY,
+ LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
+ "%s: unable to create narrow current working directory.",
+ function );
+
+ goto on_error;
+ }
+#else
narrow_current_working_directory = libcstring_narrow_string_allocate(
PATH_MAX );
@@ -3141,6 +3177,7 @@ int libcpath_path_get_current_working_di
goto on_error;
}
+#endif
narrow_current_working_directory_size = 1 + libcstring_narrow_string_length(
narrow_current_working_directory );
Reply to: