~bialix/fte-mirror/tag-fixup.before-cvs-support

« back to all changes in this revision

Viewing changes to src/s_util.cpp

  • Committer: chaac
  • Date: 2003-06-04 16:12:06 UTC
  • Revision ID: chaac_chaac-20030604161206-nmu5kl2mt1wj069v
Modified safe_strncpy() to take always maxlen as input. Removed count parameter at same time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
238
238
    return pos;
239
239
}
240
240
 
241
 
char *safe_strncpy(char *dst, const char *src, int count, int maxlen)
 
241
char *safe_strncpy(char *dst, const char *src, int maxlen)
242
242
{
243
 
    // if maxlen was specificed, clear array with NUL's
244
 
    if (maxlen != -1)
245
 
    {
246
 
        // make sure we are not trying to copy too much data
247
 
        if (count >= (maxlen - 1)) return NULL;
 
243
    // some sanity checks
 
244
    if ((dst == NULL) || (src == NULL)) return dst;
 
245
    if (maxlen <= 0) return dst;
248
246
 
249
 
        memset(dst, 0, maxlen);
250
 
    }
 
247
    // make sure we have clean destination buffer
 
248
    memset(dst, 0, maxlen);
251
249
 
252
250
    // use normal strncpy to copy actual data
253
 
    strncpy(dst, src, count);
254
 
 
255
 
    // make sure there is NUL at the end
256
 
    dst[count] = 0;
 
251
    strncpy(dst, src, maxlen - 1);
257
252
 
258
253
    return dst;
259
254
}