int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
				       const char *dir)
	{
	DIR *d;
	struct dirent *dstruct;
	int ret = 0;
	CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
	d = opendir(dir);
	if(!d)
		{
		SYSerr(SYS_F_OPENDIR, get_last_sys_error());
		ERR_add_error_data(3, "opendir('", dir, "')");
		SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
		goto err;
		}
	while((dstruct=readdir(d)))
		{
		char buf[1024];
		int r;
		if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
			{
			SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
			goto err;
			}
		r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);
		if (r <= 0 || r >= sizeof buf)
			goto err;
		if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
			goto err;
		}
	ret = 1;
err:
	CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
	return ret;
	}
['int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,\n\t\t\t\t       const char *dir)\n\t{\n\tDIR *d;\n\tstruct dirent *dstruct;\n\tint ret = 0;\n\tCRYPTO_w_lock(CRYPTO_LOCK_READDIR);\n\td = opendir(dir);\n\tif(!d)\n\t\t{\n\t\tSYSerr(SYS_F_OPENDIR, get_last_sys_error());\n\t\tERR_add_error_data(3, "opendir(\'", dir, "\')");\n\t\tSSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);\n\t\tgoto err;\n\t\t}\n\twhile((dstruct=readdir(d)))\n\t\t{\n\t\tchar buf[1024];\n\t\tint r;\n\t\tif(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tr = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);\n\t\tif (r <= 0 || r >= sizeof buf)\n\t\t\tgoto err;\n\t\tif(!SSL_add_file_cert_subjects_to_stack(stack,buf))\n\t\t\tgoto err;\n\t\t}\n\tret = 1;\nerr:\n\tCRYPTO_w_unlock(CRYPTO_LOCK_READDIR);\n\treturn ret;\n\t}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock  ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (type < 0)\n\t\t{\n\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t= CRYPTO_get_dynlock_value(type);\n\t\tif (pointer && dynlock_lock_callback)\n\t\t\t{\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\t}\n\t\tCRYPTO_destroy_dynlockid(type);\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}', 'int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,\n\t\t\t\t\tconst char *file)\n\t{\n\tBIO *in;\n\tX509 *x=NULL;\n\tX509_NAME *xn=NULL;\n\tint ret=1;\n\tint (*oldcmp)(const X509_NAME * const *a, const X509_NAME * const *b);\n\toldcmp=sk_X509_NAME_set_cmp_func(stack,xname_cmp);\n\tin=BIO_new(BIO_s_file_internal());\n\tif (in == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (!BIO_read_filename(in,file))\n\t\tgoto err;\n\tfor (;;)\n\t\t{\n\t\tif (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)\n\t\t\tbreak;\n\t\tif ((xn=X509_get_subject_name(x)) == NULL) goto err;\n\t\txn=X509_NAME_dup(xn);\n\t\tif (xn == NULL) goto err;\n\t\tif (sk_X509_NAME_find(stack,xn) >= 0)\n\t\t\tX509_NAME_free(xn);\n\t\telse\n\t\t\tsk_X509_NAME_push(stack,xn);\n\t\t}\n\tif (0)\n\t\t{\nerr:\n\t\tret=0;\n\t\t}\n\tif(in != NULL)\n\t\tBIO_free(in);\n\tif(x != NULL)\n\t\tX509_free(x);\n\tsk_X509_NAME_set_cmp_func(stack,oldcmp);\n\treturn ret;\n\t}', 'int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,const char * const *)))\n\t\t(const char * const *, const char * const *)\n\t{\n\tint (*old)(const char * const *,const char * const *)=sk->comp;\n\tif (sk->comp != c)\n\t\tsk->sorted=0;\n\tsk->comp=c;\n\treturn old;\n\t}', 'BIO_METHOD *BIO_s_file(void)\n\t{\n\treturn(&methods_filep);\n\t}', 'BIO *BIO_new(BIO_METHOD *method)\n\t{\n\tBIO *ret=NULL;\n\tret=(BIO *)OPENSSL_malloc(sizeof(BIO));\n\tif (ret == NULL)\n\t\t{\n\t\tBIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tif (!BIO_set(ret,method))\n\t\t{\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t     int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}']