File indexing completed on 2025-05-11 08:24:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <string.h>
0039 #include <inttypes.h>
0040 #include <assert.h>
0041
0042 #include <rtems/media.h>
0043
0044 char *rtems_media_create_path(
0045 const char *prefix,
0046 const char *name,
0047 rtems_device_major_number major
0048 )
0049 {
0050 size_t const size = strlen(prefix) + 1 + strlen(name) + 1 + 10 + 1;
0051 char *const s = malloc(size);
0052
0053 if (s != NULL) {
0054 #ifndef NDEBUG
0055 int rv =
0056 #endif
0057 snprintf(s, size, "%s/%s-%" PRIu32, prefix, name, major);
0058 assert(rv < (int) size);
0059 }
0060
0061 return s;
0062 }
0063
0064 char *rtems_media_replace_prefix(const char *new_prefix, const char *path)
0065 {
0066 const char *const name_try = strrchr(path, '/');
0067 const char *const name = (name_try == NULL) ? path : name_try + 1;
0068 size_t const new_prefix_len = strlen(new_prefix);
0069 size_t const name_size = strlen(name) + 1;
0070 size_t const size = new_prefix_len + 1 + name_size;
0071 char *const s = malloc(size);
0072
0073 if (s != NULL) {
0074 memcpy(s, new_prefix, new_prefix_len);
0075 s [new_prefix_len] = '/';
0076 memcpy(s + new_prefix_len + 1, name, name_size);
0077 }
0078
0079 return s;
0080 }
0081
0082 char *rtems_media_append_minor(
0083 const char *path,
0084 rtems_device_minor_number minor
0085 )
0086 {
0087 size_t const size = strlen(path) + 1 + 10 + 1;
0088 char *const s = malloc(size);
0089
0090 if (s != NULL) {
0091 #ifndef NDEBUG
0092 int rv =
0093 #endif
0094 snprintf(s, size, "%s-%" PRIu32, path, minor);
0095 assert(rv < (int) size);
0096 }
0097
0098 return s;
0099 }