|
@@ -88,7 +88,6 @@ static void free_image ( struct refcnt *refcnt ) {
|
88
|
88
|
* @ret image Executable image
|
89
|
89
|
*/
|
90
|
90
|
struct image * alloc_image ( struct uri *uri ) {
|
91
|
|
- const char *name;
|
92
|
91
|
struct image *image;
|
93
|
92
|
int rc;
|
94
|
93
|
|
|
@@ -99,23 +98,42 @@ struct image * alloc_image ( struct uri *uri ) {
|
99
|
98
|
|
100
|
99
|
/* Initialise image */
|
101
|
100
|
ref_init ( &image->refcnt, free_image );
|
102
|
|
- if ( uri ) {
|
103
|
|
- image->uri = uri_get ( uri );
|
104
|
|
- if ( uri->path ) {
|
105
|
|
- name = basename ( ( char * ) uri->path );
|
106
|
|
- if ( ( rc = image_set_name ( image, name ) ) != 0 )
|
107
|
|
- goto err_set_name;
|
108
|
|
- }
|
109
|
|
- }
|
|
101
|
+ if ( uri && ( ( rc = image_set_uri ( image, uri ) ) != 0 ) )
|
|
102
|
+ goto err_set_uri;
|
110
|
103
|
|
111
|
104
|
return image;
|
112
|
105
|
|
113
|
|
- err_set_name:
|
|
106
|
+ err_set_uri:
|
114
|
107
|
image_put ( image );
|
115
|
108
|
err_alloc:
|
116
|
109
|
return NULL;
|
117
|
110
|
}
|
118
|
111
|
|
|
112
|
+/**
|
|
113
|
+ * Set image URI
|
|
114
|
+ *
|
|
115
|
+ * @v image Image
|
|
116
|
+ * @v uri New image URI
|
|
117
|
+ * @ret rc Return status code
|
|
118
|
+ */
|
|
119
|
+int image_set_uri ( struct image *image, struct uri *uri ) {
|
|
120
|
+ const char *name;
|
|
121
|
+ int rc;
|
|
122
|
+
|
|
123
|
+ /* Set name, if image does not already have one */
|
|
124
|
+ if ( uri->path && ( ! ( image->name && image->name[0] ) ) ) {
|
|
125
|
+ name = basename ( ( char * ) uri->path );
|
|
126
|
+ if ( ( rc = image_set_name ( image, name ) ) != 0 )
|
|
127
|
+ return rc;
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ /* Update image URI */
|
|
131
|
+ uri_put ( image->uri );
|
|
132
|
+ image->uri = uri_get ( uri );
|
|
133
|
+
|
|
134
|
+ return 0;
|
|
135
|
+}
|
|
136
|
+
|
119
|
137
|
/**
|
120
|
138
|
* Set image name
|
121
|
139
|
*
|