]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/dsparse.c
Fix #undef LDAP_UFN
[openldap] / libraries / libldap / dsparse.c
index 1771d7283e73f6a17d186f8f1012807d679e1c92..2b7771c5bdf1b74dbcbf3d1d4fcbb2ff5c91cdbd 100644 (file)
@@ -1,4 +1,9 @@
+/* $OpenLDAP$ */
 /*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*  Portions
  * Copyright (c) 1993, 1994 Regents of the University of Michigan.
  * All rights reserved.
  *
  * 7 March 1994 by Mark C Smith
  */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#ifdef MACOS
-#include <stdlib.h>
-#include "macos.h"
-#else /* MACOS */
-#ifdef DOS
-#include <malloc.h>
-#include "msdos.h"
-#else /* DOS */
-#include <sys/types.h>
-#include <sys/file.h>
-#include <stdlib.h>
-#endif /* DOS */
-#endif /* MACOS */
+#include <ac/stdlib.h>
 
-#include "lber.h"
-#include "ldap.h"
+#include <ac/string.h>
+#include <ac/time.h>
 
-#ifndef NEEDPROTOS
-int next_line_tokens();
-void free_strarray();
-static int next_line();
-static char *next_token();
-#else /* !NEEDPROTOS */
-int next_line_tokens( char **bufp, long *blenp, char ***toksp );
-void free_strarray( char **sap );
-static int next_line( char **bufp, long *blenp, char **linep );
-static char *next_token( char ** sp );
-#endif /* !NEEDPROTOS */
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
+
+#include "ldap-int.h"
 
+static int next_line LDAP_P(( char **bufp, ber_len_t *blenp, char **linep ));
+static char *next_token LDAP_P(( char ** sp ));
 
 
 int
-next_line_tokens( char **bufp, long *blenp, char ***toksp )
+ldap_int_next_line_tokens( char **bufp, ber_len_t *blenp, char ***toksp )
 {
     char       *p, *line, *token, **toks;
     int                rc, tokcnt;
@@ -61,18 +50,18 @@ next_line_tokens( char **bufp, long *blenp, char ***toksp )
        return( rc );
     }
 
-    if (( toks = (char **)calloc( 1, sizeof( char * ))) == NULL ) {
-       free( line );
+    if (( toks = (char **)LDAP_CALLOC( 1, sizeof( char * ))) == NULL ) {
+       LBER_FREE( line );
        return( -1 );
     }
     tokcnt = 0;
 
     p = line;
     while (( token = next_token( &p )) != NULL ) {
-       if (( toks = (char **)realloc( toks, ( tokcnt + 2 ) *
+       if (( toks = (char **)LDAP_REALLOC( toks, ( tokcnt + 2 ) *
                sizeof( char * ))) == NULL ) {
-           free( (char *)toks );
-           free( line );
+           LBER_FREE( (char *)toks );
+           LBER_FREE( line );
            return( -1 );
        }
        toks[ tokcnt ] = token;
@@ -81,15 +70,15 @@ next_line_tokens( char **bufp, long *blenp, char ***toksp )
 
     if ( tokcnt == 1 && strcasecmp( toks[ 0 ], "END" ) == 0 ) {
        tokcnt = 0;
-       free_strarray( toks );
+       LDAP_VFREE( toks );
        toks = NULL;
     }
 
-    free( line );
+    LBER_FREE( line );
 
     if ( tokcnt == 0 ) {
        if ( toks != NULL ) {
-           free( (char *)toks );
+           LBER_FREE( (char *)toks );
        }
     } else {
        *toksp = toks;
@@ -100,10 +89,10 @@ next_line_tokens( char **bufp, long *blenp, char ***toksp )
 
 
 static int
-next_line( char **bufp, long *blenp, char **linep )
+next_line( char **bufp, ber_len_t *blenp, char **linep )
 {
     char       *linestart, *line, *p;
-    long       plen;
+    ber_slen_t plen;
 
     linestart = *bufp;
     p = *bufp;
@@ -141,12 +130,12 @@ next_line( char **bufp, long *blenp, char **linep )
        return( 0 );    /* end of file */
     }
 
-    if (( line = malloc( p - linestart )) == NULL ) {
+    if (( line = LDAP_MALLOC( p - linestart )) == NULL ) {
        *linep = NULL;
        return( -1 );   /* fatal error */
     }
 
-    (void) memcpy( line, linestart, p - linestart );
+    AC_MEMCPY( line, linestart, p - linestart );
     line[ p - linestart - 1 ] = '\0';
     *linep = line;
     return( strlen( line ));
@@ -165,7 +154,7 @@ next_token( char **sp )
 
     p = *sp;
 
-    while ( isspace( *p )) {           /* skip leading white space */
+    while ( LDAP_SPACE( (unsigned char) *p )) {        /* skip leading white space */
        ++p;
     }
 
@@ -180,7 +169,7 @@ next_token( char **sp )
     t = tokstart = p;
 
     for ( ;; ) {
-       if ( *p == '\0' || ( isspace( *p ) && !in_quote )) {
+       if ( *p == '\0' || ( LDAP_SPACE( (unsigned char) *p ) && !in_quote )) {
            if ( *p != '\0' ) {
                ++p;
            }
@@ -202,19 +191,5 @@ next_token( char **sp )
        return( NULL );
     }
 
-    return( strdup( tokstart ));
-}
-
-
-void
-free_strarray( char **sap )
-{
-    int                i;
-
-    if ( sap != NULL ) {
-       for ( i = 0; sap[ i ] != NULL; ++i ) {
-           free( sap[ i ] );
-       }
-       free( (char *)sap );
-    }
+    return( LDAP_STRDUP( tokstart ));
 }