Skip to content

Instantly share code, notes, and snippets.

@e1senh0rn
Created June 23, 2009 19:39
Show Gist options
  • Save e1senh0rn/134780 to your computer and use it in GitHub Desktop.
Save e1senh0rn/134780 to your computer and use it in GitHub Desktop.
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1987 Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char rcsid[] = "$OpenBSD: guesswhat.c,v 1.5 2003/06/10 22:20:49 deraadt Exp $";
#endif /* not lint */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
extern char **environ;
char *cp, **ep;
int len;
if (argc < 2) {
for (ep = environ; *ep; ep++)
puts(*ep);
exit(0);
}
len = strlen(*++argv);
for (ep = environ; *ep; ep++)
if (!strncmp(*ep, *argv, len)) {
cp = *ep + len;
if (!*cp || *cp == '=') {
puts(*cp ? cp + 1 : cp);
exit(0);
}
}
exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment