[image] Split image_strip_suffix() out from image_extract()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
diff --git a/src/core/archive.c b/src/core/archive.c
index bb62c7e..3d3f00c 100644
--- a/src/core/archive.c
+++ b/src/core/archive.c
@@ -43,7 +43,6 @@
*/
int image_extract ( struct image *image, const char *name,
struct image **extracted ) {
- char *dot;
int rc;
/* Check that this image can be used to extract an archive image */
@@ -66,10 +65,8 @@
}
/* Strip any archive or compression suffix from implicit name */
- if ( ( ! name ) && ( (*extracted)->name ) &&
- ( ( dot = strrchr ( (*extracted)->name, '.' ) ) != NULL ) ) {
- *dot = '\0';
- }
+ if ( ! name )
+ image_strip_suffix ( *extracted );
/* Try extracting archive image */
if ( ( rc = image->type->extract ( image, *extracted ) ) != 0 ) {
diff --git a/src/core/image.c b/src/core/image.c
index bf0e4f7..c69c05c 100644
--- a/src/core/image.c
+++ b/src/core/image.c
@@ -173,6 +173,25 @@
}
/**
+ * Strip dot suffix from image name, if present
+ *
+ * @v image Image
+ * @ret sep Position of old dot separator, or NULL
+ */
+char * image_strip_suffix ( struct image *image ) {
+ char *dot;
+
+ /* Locate and strip suffix, if present */
+ if ( image->name &&
+ ( ( dot = strrchr ( image->name, '.' ) ) != NULL ) ) {
+ *dot = '\0';
+ return dot;
+ }
+
+ return NULL;
+}
+
+/**
* Set image command line
*
* @v image Image
diff --git a/src/include/ipxe/image.h b/src/include/ipxe/image.h
index bfbf236..ca383dc 100644
--- a/src/include/ipxe/image.h
+++ b/src/include/ipxe/image.h
@@ -188,6 +188,7 @@
extern struct image * alloc_image ( struct uri *uri );
extern int image_set_uri ( struct image *image, struct uri *uri );
extern int image_set_name ( struct image *image, const char *name );
+extern char * image_strip_suffix ( struct image *image );
extern int image_set_cmdline ( struct image *image, const char *cmdline );
extern int image_set_len ( struct image *image, size_t len );
extern int image_set_data ( struct image *image, userptr_t data, size_t len );