return r;
}
-struct json_object* pakfire_json_new_object(void) {
- return json_object_new_object();
+int pakfire_json_new_object(struct json_object** json) {
+ // Make a new object
+ *json = json_object_new_object();
+
+ // Return an error if the object could not be created
+ if (!*json)
+ return -ENOMEM;
+
+ return 0;
}
int pakfire_json_add_string(struct json_object* json,
// Parse from file
int pakfire_json_parse_from_file(struct json_object** json, char** error, const char* path);
-struct json_object* pakfire_json_new_object(void);
+int pakfire_json_new_object(struct json_object** json);
int pakfire_json_add_string(struct json_object* json, const char* name, const char* value);
int pakfire_json_add_stringn(struct json_object* json, const char* name, const char* value, size_t length);
int r;
// Make a new object
- o = pakfire_json_new_object();
- if (!o) {
- r = -errno;
+ r = pakfire_json_new_object(&o);
+ if (r < 0)
goto ERROR;
- }
// Set version
r = pakfire_json_add_string(o, "imageLayoutVersion", "1.0.0");
int r;
// Make a new object
- o = pakfire_json_new_object();
- if (!o) {
- r = -errno;
+ r = pakfire_json_new_object(&o);
+ if (r < 0)
goto ERROR;
- }
// Set schema version
r = pakfire_json_add_int64(o, "schemaVersion", 2);
struct json_object* diffids = NULL;
// Make a new object
- o = pakfire_json_new_object();
- if (!o) {
- r = -errno;
+ r = pakfire_json_new_object(&o);
+ if (r < 0)
goto ERROR;
- }
// Format creation timestamp
r = pakfire_strftime_now(created, "%Y-%m-%dT%H:%M:%SZ");
int r;
// Make a new object
- o = pakfire_json_new_object();
- if (!o) {
- r = -errno;
+ r = pakfire_json_new_object(&o);
+ if (r < 0)
goto ERROR;
- }
// Set schema version
r = pakfire_json_add_int64(o, "schemaVersion", 2);
goto ERROR;
// Make another new object
- manifest = pakfire_json_new_object();
- if (!manifest) {
- r = -errno;
+ r = pakfire_json_new_object(&manifest);
+ if (r < 0)
goto ERROR;
- }
// Add media type
r = pakfire_json_add_string(manifest, "mediaType", "application/vnd.oci.image.manifest.v1+json");
goto ERROR;
// Create a new JSON object
- json = pakfire_json_new_object();
- if (!json) {
- r = -errno;
+ r = pakfire_json_new_object(&json);
+ if (r < 0)
goto ERROR;
- }
// Add the media type
r = pakfire_json_add_string(json, "mediaType", "application/vnd.oci.image.layer.v1.tar+gzip");
int r;
// Reference to the config
- writer.config = json_object_new_object();
- if (!writer.config) {
- r = -errno;
+ r = pakfire_json_new_object(&writer.config);
+ if (r < 0)
goto ERROR;
- }
// To store all layers
writer.layers = json_object_new_array();
}
// Create a new object
- file = pakfire_json_new_object();
- if (!file) {
- ERROR(self->ctx, "Failed to create a new file object: %m\n");
- r = -errno;
+ r = pakfire_json_new_object(&file);
+ if (r < 0) {
+ ERROR(self->ctx, "Failed to create a new file object: %s\n", strerror(-r));
goto ERROR;
}