Skip to content

Commit ecc3014

Browse files
committed
Remove stdstring dependency from a few files
1 parent 0dffc7b commit ecc3014

File tree

3 files changed

+44
-52
lines changed

3 files changed

+44
-52
lines changed

tasks/task_decompress.c

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17-
#include <string/stdstring.h>
1817
#include <file/file_path.h>
1918
#include <file/archive_file.h>
2019
#include <retro_miscellaneous.h>
@@ -266,11 +265,9 @@ static bool task_decompress_finder(
266265
retro_task_t *task, void *user_data)
267266
{
268267
decompress_state_t *dec = (decompress_state_t*)task->state;
269-
270268
if (task->handler != task_decompress_handler)
271269
return false;
272-
273-
return string_is_equal(dec->source_file, (const char*)user_data);
270+
return !strcmp(dec->source_file, (const char*)user_data);
274271
}
275272

276273
bool task_check_decompress(const char *source_file)
@@ -301,90 +298,91 @@ void *task_push_decompress(
301298
const char *ext = NULL;
302299
decompress_state_t *s = NULL;
303300
retro_task_t *t = NULL;
304-
305301
tmp[0] = '\0';
306-
307-
if (string_is_empty(target_dir) || string_is_empty(source_file))
302+
if (!target_dir || !*target_dir || !source_file || !*source_file)
308303
return NULL;
309-
310304
ext = path_get_extension(source_file);
311-
312305
/* ZIP or APK only */
313306
if (
314307
!path_is_valid(source_file) ||
315308
(
316-
!string_is_equal_noncase(ext, "zip")
317-
&& !string_is_equal_noncase(ext, "apk")
309+
strcasecmp(ext, "zip") != 0
310+
&& strcasecmp(ext, "apk") != 0
318311
#ifdef HAVE_7ZIP
319-
&& !string_is_equal_noncase(ext, "7z")
312+
&& strcasecmp(ext, "7z") != 0
320313
#endif
321314
#ifdef HAVE_ZSTD
322-
&& !string_is_equal_noncase(ext, "zst")
315+
&& strcasecmp(ext, "zst") != 0
323316
#endif
324317
)
325318
)
326319
return NULL;
327-
328320
if (!valid_ext || !valid_ext[0])
329321
valid_ext = NULL;
330-
331322
if (task_check_decompress(source_file))
332323
return NULL;
333-
334324
if (!(s = (decompress_state_t*)calloc(1, sizeof(*s))))
335325
return NULL;
336-
337326
if (!(t = task_init()))
338327
{
339328
free(s);
340329
return NULL;
341330
}
342-
343331
s->source_file = strdup(source_file);
344332
s->target_dir = strdup(target_dir);
345-
333+
if (!s->source_file || !s->target_dir)
334+
goto error;
346335
s->valid_ext = valid_ext ? strdup(valid_ext) : NULL;
347336
s->archive.type = ARCHIVE_TRANSFER_INIT;
348337
s->userdata = (struct archive_extract_userdata*)
349338
calloc(1, sizeof(*s->userdata));
350-
339+
if (!s->userdata)
340+
goto error;
351341
t->frontend_userdata= frontend_userdata;
352-
353342
t->state = s;
354343
t->handler = task_decompress_handler;
355-
356-
if (!string_is_empty(subdir))
344+
if (subdir && *subdir)
357345
{
358346
s->subdir = strdup(subdir);
347+
if (!s->subdir)
348+
goto error;
359349
t->handler = task_decompress_handler_subdir;
360350
}
361-
else if (!string_is_empty(target_file))
351+
else if (target_file && *target_file)
362352
{
363353
s->target_file = strdup(target_file);
354+
if (!s->target_file)
355+
goto error;
364356
t->handler = task_decompress_handler_target_file;
365357
}
366-
367358
t->callback = cb;
368359
t->user_data = user_data;
369-
370360
_len = strlcpy(tmp,
371361
msg_hash_to_str(MSG_EXTRACTING), sizeof(tmp));
372362
tmp[ _len] = ':';
373363
tmp[++_len] = ' ';
374364
tmp[++_len] = '\0';
375-
_len += strlcpy(tmp + _len,
365+
strlcpy(tmp + _len,
376366
path_basename(source_file),
377367
sizeof(tmp) - _len);
378-
tmp[++_len] = '\0';
379-
380368
t->title = strdup(tmp);
369+
if (!t->title)
370+
goto error;
381371
t->flags |= RETRO_TASK_FLG_ALTERNATIVE_LOOK;
382372
if (mute)
383373
t->flags |= RETRO_TASK_FLG_MUTE;
384374
else
385375
t->flags &= ~RETRO_TASK_FLG_MUTE;
386-
387376
task_queue_push(t);
388-
389377
return t;
378+
error:
379+
free(s->source_file);
380+
free(s->target_dir);
381+
free(s->valid_ext);
382+
free(s->subdir);
383+
free(s->target_file);
384+
free(s->userdata);
385+
free(s);
386+
free(t);
387+
return NULL;
390388
}

tasks/task_file_transfer.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include <compat/strl.h>
1919
#include <retro_miscellaneous.h>
2020

21-
#include <string/stdstring.h>
22-
2321
#ifdef HAVE_AUDIOMIXER
2422
#include "task_audio_mixer.h"
2523
#endif
@@ -62,41 +60,39 @@ void task_file_load_handler(retro_task_t *task)
6260
{
6361
uint8_t flg;
6462
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
65-
6663
if (nbio)
6764
{
6865
switch (nbio->status)
6966
{
7067
case NBIO_STATUS_INIT:
71-
if (nbio && !string_is_empty(nbio->path))
68+
if (nbio->path)
7269
{
7370
struct nbio_t *handle = (struct nbio_t*)nbio_open(nbio->path, NBIO_READ);
74-
7571
if (handle)
7672
{
7773
nbio->handle = handle;
7874
nbio->status = NBIO_STATUS_TRANSFER;
79-
8075
nbio_begin_read(handle);
8176
return;
8277
}
83-
8478
task_set_flags(task, RETRO_TASK_FLG_CANCELLED, true);
8579
}
8680
break;
8781
case NBIO_STATUS_TRANSFER_PARSE:
88-
if (!nbio || task_file_transfer_iterate_parse(nbio) == -1)
82+
if (task_file_transfer_iterate_parse(nbio) == -1)
83+
{
8984
task_set_flags(task, RETRO_TASK_FLG_CANCELLED, true);
85+
break;
86+
}
9087
nbio->status = NBIO_STATUS_TRANSFER_FINISHED;
9188
break;
9289
case NBIO_STATUS_TRANSFER:
93-
if (!nbio || task_file_transfer_iterate_transfer(nbio) == -1)
90+
if (task_file_transfer_iterate_transfer(nbio) == -1)
9491
nbio->status = NBIO_STATUS_TRANSFER_PARSE;
9592
break;
9693
case NBIO_STATUS_TRANSFER_FINISHED:
9794
break;
9895
}
99-
10096
switch (nbio->type)
10197
{
10298
case NBIO_TYPE_PNG:
@@ -123,9 +119,7 @@ void task_file_load_handler(retro_task_t *task)
123119
break;
124120
}
125121
}
126-
127122
flg = task_get_flags(task);
128-
129123
if ((flg & RETRO_TASK_FLG_CANCELLED) > 0)
130124
{
131125
task_set_error(task, strldup("Task canceled.", sizeof("Task canceled.")));

tasks/task_image.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <file/nbio.h>
2222
#include <formats/image.h>
2323
#include <compat/strl.h>
24-
#include <string/stdstring.h>
2524
#include <retro_miscellaneous.h>
2625
#include <features/features_cpu.h>
2726

@@ -89,7 +88,7 @@ static int cb_image_upload_generic(void *data, size_t len)
8988
image->flags &= ~IMAGE_FLAG_IS_BLOCKING_ON_PROCESSING;
9089
image->flags |= IMAGE_FLAG_IS_BLOCKING;
9190
image->flags |= IMAGE_FLAG_IS_FINISHED;
92-
nbio->is_finished = true;
91+
nbio->is_finished = true;
9392

9493
return 0;
9594
}
@@ -124,8 +123,8 @@ static int cb_image_thumbnail(void *data, size_t len)
124123
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
125124
int retval = image ? task_image_process(image, &width, &height) : IMAGE_PROCESS_ERROR;
126125

127-
if ((retval == IMAGE_PROCESS_ERROR) ||
128-
(retval == IMAGE_PROCESS_ERROR_END)
126+
if ( (retval == IMAGE_PROCESS_ERROR)
127+
|| (retval == IMAGE_PROCESS_ERROR_END)
129128
)
130129
return -1;
131130

@@ -151,7 +150,8 @@ static int task_image_iterate_process_transfer(struct nbio_image_handle *image)
151150

152151
do
153152
{
154-
if ((retval = task_image_process(image, &width, &height)) != IMAGE_PROCESS_NEXT)
153+
if ((retval = task_image_process(image, &width, &height))
154+
!= IMAGE_PROCESS_NEXT)
155155
break;
156156
}while (cpu_features_get_time_usec() - start_time
157157
< image->frame_duration);
@@ -371,10 +371,10 @@ bool task_image_load_handler(retro_task_t *task)
371371
&& ((image->ti.width < image->upscale_threshold)
372372
|| (image->ti.height < image->upscale_threshold)))
373373
{
374-
unsigned min_size = (image->ti.width < image->ti.height)
375-
? image->ti.width : image->ti.height;
376-
unsigned scale_factor_int = ((image->upscale_threshold + min_size - 1)
377-
/ min_size);
374+
unsigned min_size = (image->ti.width < image->ti.height)
375+
? image->ti.width : image->ti.height;
376+
unsigned scale_factor_int = ((image->upscale_threshold
377+
+ min_size - 1) / min_size);
378378
struct texture_image img_resampled = {
379379
NULL,
380380
0,

0 commit comments

Comments
 (0)