Print this page
8485 Remove set but unused variables in usr/src/cmd
   1 /*

   2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 
   6 /* 
   7  * The contents of this file are subject to the Netscape Public
   8  * License Version 1.1 (the "License"); you may not use this file
   9  * except in compliance with the License. You may obtain a copy of
  10  * the License at http://www.mozilla.org/NPL/
  11  *  
  12  * Software distributed under the License is distributed on an "AS
  13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  14  * implied. See the License for the specific language governing
  15  * rights and limitations under the License.
  16  *  
  17  * The Original Code is Mozilla Communicator client code, released
  18  * March 31, 1998.
  19  * 
  20  * The Initial Developer of the Original Code is Netscape
  21  * Communications Corporation. Portions created by Netscape are


 343     return( rc );
 344 } 
 345 
 346 
 347 /*
 348  * Populate *bvp with the contents of the file named by "path".
 349  *
 350  * If reporterrs is non-zero, specific error messages are printed to
 351  * stderr.
 352  *
 353  * If successful, LDAPTOOL_FILEURL_SUCCESS is returned and bvp->bv_len
 354  * and bvp->bv_val are set (the latter is set to malloc'd memory).
 355  * Upon failure, a different LDAPTOOL_FILEURL_ error code is returned.
 356  */
 357 
 358 static int
 359 berval_from_file( const char *path, struct berval *bvp, int reporterrs )
 360 {
 361     FILE        *fp;
 362     long        rlen;
 363     int         eof;
 364 #if defined( XP_WIN32 )
 365     char        mode[20] = "r+b";
 366 #else
 367     char        mode[20] = "r";
 368 #endif
 369 
 370 #ifdef SOLARIS_LDAP_CMD
 371     if (( fp = fopen( path, mode )) == NULL ) {
 372 #else
 373     if (( fp = ldaptool_open_file( path, mode )) == NULL ) {
 374 #endif  /* SOLARIS_LDAP_CMD */
 375         if ( reporterrs ) perror( path );
 376         return( LDAPTOOL_FILEURL_FILEIOERROR );
 377     }
 378 
 379     if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
 380         if ( reporterrs ) perror( path );
 381         fclose( fp );
 382         return( LDAPTOOL_FILEURL_FILEIOERROR );
 383     }
 384 
 385     bvp->bv_len = ftell( fp );
 386 
 387     if (( bvp->bv_val = (char *)malloc( bvp->bv_len + 1 )) == NULL ) {
 388         if ( reporterrs ) perror( "malloc" );
 389         fclose( fp );
 390         return( LDAPTOOL_FILEURL_NOMEMORY );
 391     }
 392 
 393     if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
 394         if ( reporterrs ) perror( path );
 395         fclose( fp );
 396         return( LDAPTOOL_FILEURL_FILEIOERROR );
 397     }
 398 
 399     rlen = fread( bvp->bv_val, 1, bvp->bv_len, fp );
 400     eof = feof( fp );
 401     fclose( fp );
 402 
 403     if ( rlen != (long)bvp->bv_len ) {
 404         if ( reporterrs ) perror( path );
 405         free( bvp->bv_val );
 406         return( LDAPTOOL_FILEURL_FILEIOERROR );
 407     }
 408 
 409     bvp->bv_val[ bvp->bv_len ] = '\0';
 410     return( LDAPTOOL_FILEURL_SUCCESS );
 411 }
 412 
 413 
 414 /*
 415  * Return a non-zero value if the string s begins with prefix and zero if not.
 416  */
 417 static int
 418 str_starts_with( const char *s, char *prefix )
 419 {
 420     size_t      prefix_len;


   1 /*
   2  * Copyright 2017 Gary Mills
   3  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
   4  * Use is subject to license terms.
   5  */
   6 
   7 /* 
   8  * The contents of this file are subject to the Netscape Public
   9  * License Version 1.1 (the "License"); you may not use this file
  10  * except in compliance with the License. You may obtain a copy of
  11  * the License at http://www.mozilla.org/NPL/
  12  *  
  13  * Software distributed under the License is distributed on an "AS
  14  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  15  * implied. See the License for the specific language governing
  16  * rights and limitations under the License.
  17  *  
  18  * The Original Code is Mozilla Communicator client code, released
  19  * March 31, 1998.
  20  * 
  21  * The Initial Developer of the Original Code is Netscape
  22  * Communications Corporation. Portions created by Netscape are


 344     return( rc );
 345 } 
 346 
 347 
 348 /*
 349  * Populate *bvp with the contents of the file named by "path".
 350  *
 351  * If reporterrs is non-zero, specific error messages are printed to
 352  * stderr.
 353  *
 354  * If successful, LDAPTOOL_FILEURL_SUCCESS is returned and bvp->bv_len
 355  * and bvp->bv_val are set (the latter is set to malloc'd memory).
 356  * Upon failure, a different LDAPTOOL_FILEURL_ error code is returned.
 357  */
 358 
 359 static int
 360 berval_from_file( const char *path, struct berval *bvp, int reporterrs )
 361 {
 362     FILE        *fp;
 363     long        rlen;

 364 #if defined( XP_WIN32 )
 365     char        mode[20] = "r+b";
 366 #else
 367     char        mode[20] = "r";
 368 #endif
 369 
 370 #ifdef SOLARIS_LDAP_CMD
 371     if (( fp = fopen( path, mode )) == NULL ) {
 372 #else
 373     if (( fp = ldaptool_open_file( path, mode )) == NULL ) {
 374 #endif  /* SOLARIS_LDAP_CMD */
 375         if ( reporterrs ) perror( path );
 376         return( LDAPTOOL_FILEURL_FILEIOERROR );
 377     }
 378 
 379     if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
 380         if ( reporterrs ) perror( path );
 381         fclose( fp );
 382         return( LDAPTOOL_FILEURL_FILEIOERROR );
 383     }
 384 
 385     bvp->bv_len = ftell( fp );
 386 
 387     if (( bvp->bv_val = (char *)malloc( bvp->bv_len + 1 )) == NULL ) {
 388         if ( reporterrs ) perror( "malloc" );
 389         fclose( fp );
 390         return( LDAPTOOL_FILEURL_NOMEMORY );
 391     }
 392 
 393     if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
 394         if ( reporterrs ) perror( path );
 395         fclose( fp );
 396         return( LDAPTOOL_FILEURL_FILEIOERROR );
 397     }
 398 
 399     rlen = fread( bvp->bv_val, 1, bvp->bv_len, fp );

 400     fclose( fp );
 401 
 402     if ( rlen != (long)bvp->bv_len ) {
 403         if ( reporterrs ) perror( path );
 404         free( bvp->bv_val );
 405         return( LDAPTOOL_FILEURL_FILEIOERROR );
 406     }
 407 
 408     bvp->bv_val[ bvp->bv_len ] = '\0';
 409     return( LDAPTOOL_FILEURL_SUCCESS );
 410 }
 411 
 412 
 413 /*
 414  * Return a non-zero value if the string s begins with prefix and zero if not.
 415  */
 416 static int
 417 str_starts_with( const char *s, char *prefix )
 418 {
 419     size_t      prefix_len;