11.3Smaya/* $NetBSD: t_dlerror-cleared.c,v 1.3 2019/07/09 16:24:01 maya Exp $ */ 21.1Sskrll 31.1Sskrll/* 41.1Sskrll * Copyright (c) 2009 The NetBSD Foundation, Inc. 51.1Sskrll * All rights reserved. 61.1Sskrll * 71.1Sskrll * Redistribution and use in source and binary forms, with or without 81.1Sskrll * modification, are permitted provided that the following conditions 91.1Sskrll * are met: 101.1Sskrll * 1. Redistributions of source code must retain the above copyright 111.1Sskrll * notice, this list of conditions and the following disclaimer. 121.1Sskrll * 2. Redistributions in binary form must reproduce the above copyright 131.1Sskrll * notice, this list of conditions and the following disclaimer in the 141.1Sskrll * documentation and/or other materials provided with the distribution. 151.1Sskrll * 161.1Sskrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 171.1Sskrll * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 181.1Sskrll * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 191.1Sskrll * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 201.1Sskrll * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 211.1Sskrll * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221.1Sskrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 231.1Sskrll * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 241.1Sskrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 251.1Sskrll * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 261.1Sskrll * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 271.1Sskrll * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 281.1Sskrll */ 291.1Sskrll 301.1Sskrll#include <sys/types.h> 311.1Sskrll 321.1Sskrll#include <atf-c.h> 331.1Sskrll#include <dlfcn.h> 341.1Sskrll#include <link_elf.h> 351.1Sskrll 361.2Schristos#include "h_macros.h" 371.1Sskrll 381.1SskrllATF_TC(rtld_dlerror_cleared); 391.1SskrllATF_TC_HEAD(rtld_dlerror_cleared, tc) 401.1Sskrll{ 411.1Sskrll atf_tc_set_md_var(tc, "descr", 421.1Sskrll "error set by dlopen persists past a successful dlopen call"); 431.1Sskrll} 441.1Sskrll 451.1SskrllATF_TC_BODY(rtld_dlerror_cleared, tc) 461.1Sskrll{ 471.1Sskrll void *handle; 481.1Sskrll char *error; 491.1Sskrll 501.1Sskrll /* 511.1Sskrll * Test that an error set by dlopen() persists past a successful 521.1Sskrll * dlopen() call. 531.1Sskrll */ 541.1Sskrll handle = dlopen("libnonexistent.so", RTLD_LAZY); 551.1Sskrll ATF_CHECK(handle == NULL); 561.1Sskrll handle = dlopen("libm.so", RTLD_NOW); 571.1Sskrll ATF_CHECK(handle); 581.1Sskrll error = dlerror(); 591.1Sskrll ATF_CHECK(error); 601.1Sskrll 611.1Sskrll} 621.1Sskrll 631.1SskrllATF_TP_ADD_TCS(tp) 641.1Sskrll{ 651.1Sskrll ATF_TP_ADD_TC(tp, rtld_dlerror_cleared); 661.3Smaya return atf_no_error(); 671.1Sskrll} 68