Logo Search packages:      
Sourcecode: likewise-open version File versions

char* alpha_strcpy_fn ( const char *  fn,
int  line,
char *  dest,
const char *  src,
const char *  other_safe_chars,
size_t  maxlength 
)

Paranoid strcpy into a buffer of given length (includes terminating zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars and replaces with '_'. Deliberately does *NOT* check for multibyte characters. Don't change it !

Definition at line 769 of file util_str.c.

References strchr_m().

{
      size_t len, i;

#ifdef DEVELOPER
      clobber_region(fn, line, dest, maxlength);
#endif

      if (!dest) {
            DEBUG(0,("ERROR: NULL dest in alpha_strcpy, "
                  "called from [%s][%d]\n", fn, line));
            return NULL;
      }

      if (!src) {
            *dest = 0;
            return dest;
      }

      len = strlen(src);
      if (len >= maxlength)
            len = maxlength - 1;

      if (!other_safe_chars)
            other_safe_chars = "";

      for(i = 0; i < len; i++) {
            int val = (src[i] & 0xff);
            if (isupper_ascii(val) || islower_ascii(val) ||
                        isdigit(val) || strchr_m(other_safe_chars, val))
                  dest[i] = src[i];
            else
                  dest[i] = '_';
      }

      dest[i] = '\0';

      return dest;
}


Generated by  Doxygen 1.6.0   Back to index