Skip to content

Commit

Permalink
[image] Split image_strip_suffix() out from image_extract()
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <[email protected]>
  • Loading branch information
mcb30 committed Aug 29, 2024
1 parent 748cab7 commit 49404bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/core/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 ) {
Expand Down
19 changes: 19 additions & 0 deletions src/core/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions src/include/ipxe/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 49404bf

Please sign in to comment.