Fao said:
By the way, this while loop also assumes that "name" is a properly
fomatted C string.
Not necessarily. Its behavior is well-defined if name points to an
array of characters that includes a '.' character, even if there's no
trailing '\0'. (The following strncmp() and printf() calls make some
more assumptions; I'm too lazy to work out the details, but note that
the arguments to strncmp() needn't point to strings.)
Some cases the OP should consider are:
"" (empty string)
"foobar" (no '.')
"foo.bar.jpg" (multiple '.'s)
"foo.JPG" (matches, but case-insensitively)
"foobar.jpgggg" (matches ".jpg", but with extra characters)
Other edge cases are a null pointer and a pointer to a character array
not terminated by a '\0'; it might suffice to treat these as undefined
behavior (errors that should have been caught by the caller).
Another edge case is an invalid non-null pointer, such as one that
points to an object that no longer exists. This isn't worth worrying
about, since there's no portable way to detect it, and the program
will have invoked undefined behavior just by evaluating it, before the
function is even called.