]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[image] Split image_strip_suffix() out from image_extract()
authorMichael Brown <mcb30@ipxe.org>
Thu, 29 Aug 2024 12:08:27 +0000 (13:08 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 29 Aug 2024 12:09:41 +0000 (13:09 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/archive.c
src/core/image.c
src/include/ipxe/image.h

index bb62c7e4783c27a8f5e1cafcc5ef5d9763744129..3d3f00cc6d0a9caf0f2cb7ccaa0284076936f4e9 100644 (file)
@@ -43,7 +43,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  */
 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 @@ int image_extract ( struct image *image, const char *name,
        }
 
        /* 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 ) {
index bf0e4f756386626e1b7a8b751cf367871c352c03..c69c05c93c4ed5b67033462eaa2130ef347f4caa 100644 (file)
@@ -172,6 +172,25 @@ int image_set_name ( struct image *image, const char *name ) {
        return 0;
 }
 
+/**
+ * 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
  *
index bfbf23687c424e2c2cc9f402dadc014b25e7a374..ca383dc7b38979c40e2e8d6b05e1701ac2ec33c5 100644 (file)
@@ -188,6 +188,7 @@ static inline struct image * first_image ( void ) {
 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 );