#include <dlfcn.h>
#include <link.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <libintl.h>
#include <locale.h>
#include <conv.h>
#include <msg.h>
void
locale()
{
static int localeinit = 0;
if (localeinit++)
return;
(void) setlocale(LC_MESSAGES, MSG_ORIG(MSG_STR_EMPTY));
(void) textdomain(MSG_ORIG(MSG_SUNW_OST_SGS));
}
const char *
_moe_msg(Msg mid)
{
return (gettext(MSG_ORIG(mid)));
}
static char *
trim_msg(char *str)
{
char *ptr = str;
int cnt = 0;
while (*ptr) {
if (*ptr == ':') {
if (++cnt == 3)
break;
}
ptr++;
}
if (*ptr == '\0')
return (str);
else
return (ptr + 2);
}
#define ONLY32 1
#define ONLY64 2
static int
openlib(const char *prog, const char *name, int class, int silent, int verbose)
{
void *handle;
const char *modestr;
if (class) {
locale();
#if defined(_LP64)
modestr = MSG_INTL(MSG_PRE_64);
#else
modestr = MSG_INTL(MSG_PRE_32);
#endif
} else
modestr = MSG_ORIG(MSG_STR_EMPTY);
if ((handle = dlmopen(LM_ID_NEWLM, name,
(RTLD_FIRST | RTLD_CONFGEN | RTLD_LAZY))) == 0) {
if (verbose) {
(void) fprintf(stderr, MSG_ORIG(MSG_FMT_VERBOSE), prog,
modestr, trim_msg(dlerror()));
(void) fflush(stderr);
}
return (1);
}
if (silent == 0) {
Link_map *lmp;
if (dlinfo(handle, RTLD_DI_LINKMAP, &lmp) == -1) {
if (verbose) {
(void) fprintf(stderr,
MSG_ORIG(MSG_FMT_VERBOSE), prog, modestr,
trim_msg(dlerror()));
(void) fflush(stderr);
}
return (1);
}
if (verbose)
(void) printf(MSG_ORIG(MSG_FMT_VERBOSE), prog, modestr,
lmp->l_name);
else
(void) printf(MSG_ORIG(MSG_FMT_SIMPLE), modestr,
lmp->l_name);
(void) fflush(stdout);
}
(void) dlclose(handle);
return (0);
}
int
main(int argc, char **argv, char **envp)
{
int var, verbose = 0, silent = 0, error = 0, mode = 0, class = 0;
char *prog;
if ((prog = strrchr(argv[0], '/')) == 0)
prog = argv[0];
else
prog++;
opterr = 0;
while ((var = getopt(argc, argv, MSG_ORIG(MSG_STR_OPTIONS))) != EOF) {
switch (var) {
case 'c':
class++;
break;
case '3':
#if !defined(_LP64)
if ((optarg[0] == '2') && (mode == 0))
mode = ONLY32;
else
#endif
error++;
break;
case '6':
if ((optarg[0] == '4') && (mode == 0))
mode = ONLY64;
else
error++;
break;
case 's':
if (verbose == 0)
silent++;
else
error++;
break;
case 'v':
if (silent == 0)
verbose++;
else
error++;
break;
case '?':
error++;
break;
default:
break;
}
}
if (error || ((argc - optind) == 0)) {
locale();
(void) fprintf(stderr, MSG_INTL(MSG_ARG_USAGE), prog);
return (1);
}
if (silent)
class = 0;
#if !defined(_LP64)
if (mode != ONLY64) {
#endif
if (openlib(prog, argv[optind], class, silent, verbose) != 0) {
if (mode)
error++;
}
#if !defined(_LP64)
}
#endif
if (mode == ONLY32)
return (error);
#if !defined(__sparcv9) && !defined(__amd64)
(void) conv_check_native(argv, envp);
#endif
return (error);
}