MCPcopy Create free account
hub / github.com/OpenPrinting/cups / _cupsStrAlloc

Function _cupsStrAlloc

cups/string.c:44–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 */
43
44char * /* O - String pointer */
45_cupsStrAlloc(const char *s) /* I - String */
46{
47 size_t slen; /* Length of string */
48 _cups_sp_item_t *item, /* String pool item */
49 *key; /* Search key */
50
51
52 /*
53 * Range check input...
54 */
55
56 if (!s)
57 return (NULL);
58
59 /*
60 * Get the string pool...
61 */
62
63 _cupsMutexLock(&sp_mutex);
64
65 if (!stringpool)
66 stringpool = cupsArrayNew((cups_array_func_t)compare_sp_items, NULL);
67
68 if (!stringpool)
69 {
70 _cupsMutexUnlock(&sp_mutex);
71
72 return (NULL);
73 }
74
75 /*
76 * See if the string is already in the pool...
77 */
78
79 key = (_cups_sp_item_t *)(s - offsetof(_cups_sp_item_t, str));
80
81 if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, key)) != NULL)
82 {
83 /*
84 * Found it, return the cached string...
85 */
86
87 item->ref_count ++;
88
89#ifdef DEBUG_GUARDS
90 DEBUG_printf(("5_cupsStrAlloc: Using string %p(%s) for \"%s\", guard=%08x, "
91 "ref_count=%d", item, item->str, s, item->guard,
92 item->ref_count));
93
94 if (item->guard != _CUPS_STR_GUARD)
95 abort();
96#endif /* DEBUG_GUARDS */
97
98 _cupsMutexUnlock(&sp_mutex);
99
100 return (item->str);
101 }

Callers 15

cupsdCopyLocationFunction · 0.85
cupsdNewLocationFunction · 0.85
copy_authmaskFunction · 0.85
add_printerFunction · 0.85
copy_printer_attrsFunction · 0.85
update_job_attrsFunction · 0.85
cupsdReadConfigurationFunction · 0.85
cupsdLoadAllClassesFunction · 0.85
cupsdCreateCommonDataFunction · 0.85
cupsdLoadAllPrintersFunction · 0.85
cupsdSetPrinterAttrFunction · 0.85
cupsdSetPrinterAttrsFunction · 0.85

Calls 5

_cupsMutexLockFunction · 0.85
cupsArrayNewFunction · 0.85
_cupsMutexUnlockFunction · 0.85
cupsArrayFindFunction · 0.85
cupsArrayAddFunction · 0.85

Tested by

no test coverage detected