cybersecurity · beginner · ~10 min
Pre-check the mkstemp contract.
Implement int valid_mkstemp_template(const char *t).
Return 1 if t is non-NULL and ends with at least 6 consecutive X chars
(any longer suffix of X is fine, e.g. /tmp/cplat-XXXXXXXX is fine). Else 0.
mkstemp mutates its template in place. If the template lacks the trailing 'XXXXXX', the call fails or — on some old glibcs — produces predictable names. A defensive wrapper checks the template first.
Null-terminated string.
0/1.
Pure string scan.
int valid_mkstemp_template(const char *t) { /* TODO */ (void)t; return 0; }
Requiring EXACTLY 6 X's. Any suffix of >= 6 X's is fine.
Empty string. String shorter than 6 chars. All X's.
O(strlen).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.