On Wed, Jan 7, 2015 at 4:00 PM, niXman <i.nix...@autistici.org> wrote:
>> +int __cdecl mkstemp (char *template_name)
>> +{
>> +    errno_t ec;
>> +    int i, j, fd, len, index;
>> +
>> +    /* These are the (62) characters used in temporary filenames. */
>> +    static const char letters[] =
>> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
>> +
>> +    /* The last six characters of template must be "XXXXXX" */
>> +    if (template_name == NULL || (len = strlen (template_name)) < 6
>> +            || memcmp (template_name + (len - 6), "XXXXXX", 6)) {
>> +        errno = EINVAL;
>> +        return -1;
>> +    }
>
> It will be better if "XXXXXX" and '6' will be variables:
> static const char x_template[] = "XXXXXX";
> static const int x_template_len = sizeof(x_template)-1;
>

Since the last 6 characters must be "XXXXXX" is mandatory, I think no
need such tricks.

> and the test for 'template_name == NULL' I propose to move to the top of
> the function.
>
> in this case, the code look like this:
> if (template_name == NULL) {
>      errno = EINVAL;
>      return -1;
> }
>

I think the merged condition statement is not very complicated.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to