]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/ldif.c
Import ksp's changes to support newer versions of DB2 (ITS#27).
[openldap] / servers / slapd / tools / ldif.c
index dc9f25d584e9d80d46c4ee47bff1c4541c53d554..0f4b2ebb67ae5b3e50c9b5b90278471661acaac3 100644 (file)
@@ -1,8 +1,12 @@
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <stdlib.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+#include <ac/unistd.h>                 /* Get read() */
+
 #include "lber.h"
 #include "ldap.h"
 #include "ldif.h"
@@ -11,20 +15,19 @@ int ldap_syslog;
 int    ldap_syslog_level;
 
 
-usage( name )
-char   *name;
+static void
+usage( char *name )
 {
        fprintf( stderr, "usage: %s [-b] <attrtype>\n", name );
        exit( 1 );
 }
 
-main( argc, argv )
-    int                argc;
-    char       **argv;
+int
+main( int argc, char **argv )
 {
        char    buf[BUFSIZ];
        char    *type, *out;
-       int     binary = 0;
+       int     len, binary = 0;
 
        if (argc < 2 || argc > 3 ) {
                usage( argv[0] );
@@ -79,7 +82,9 @@ main( argc, argv )
        }
 
        /* not binary:  one value per line... */
-       while ( gets( buf ) != NULL ) {
+       while ( fgets( buf, sizeof(buf), stdin ) != NULL ) {
+               if( buf[len=strlen(buf)] == '\n') buf[len] = '\0';
+
                if (( out = ldif_type_and_value( type, buf, strlen( buf ) ))
                    == NULL ) {
                        perror( "ldif_type_and_value" );