(root)/
acl-2.3.1/
libmisc/
unquote.c
       1  /*
       2    File: unquote.c
       3  
       4    Copyright (C) 2003 Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
       5  
       6    This program is free software; you can redistribute it and/or modify it under
       7    the terms of the GNU Lesser General Public License as published by the
       8    Free Software Foundation; either version 2.1 of the License, or (at
       9    your option) any later version.
      10  
      11    This program is distributed in the hope that it will be useful, but WITHOUT
      12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
      14    License for more details.
      15  
      16    You should have received a copy of the GNU Lesser General Public
      17    License along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18  */
      19  
      20  #include "config.h"
      21  #include <stdio.h>
      22  #include <stdlib.h>
      23  #include <ctype.h>
      24  #include "misc.h"
      25  
      26  char *__acl_unquote(char *str)
      27  {
      28  	unsigned char *s, *t;
      29  
      30  	if (!str)
      31  		return str;
      32  
      33  	for (s = (unsigned char *)str; *s != '\0'; s++)
      34  		if (*s == '\\')
      35  			break;
      36  	if (*s == '\0')
      37  		return str;
      38  
      39  #define isoctal(c) \
      40  	((c) >= '0' && (c) <= '7')
      41  
      42  	t = s;
      43  	do {
      44  		if (*s == '\\' &&
      45  		    isoctal(*(s+1)) && isoctal(*(s+2)) && isoctal(*(s+3))) {
      46  			*t++ = ((*(s+1) - '0') << 6) +
      47  			       ((*(s+2) - '0') << 3) +
      48  			       ((*(s+3) - '0')     );
      49  			s += 3;
      50  		} else if (*s == '\\' && *(s+1) == '\\') {
      51  			*t++ = *s++;
      52  		} else
      53  			*t++ = *s;
      54  	} while (*s++ != '\0');
      55  
      56  	return str;
      57  }