Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

GNU/Hello World

Name: Anonymous 2011-01-10 18:54

#include </usr/include/aio.h>
#include </usr/include/aliases.h>
#include </usr/include/alloca.h>
#include </usr/include/a.out.h>
#include </usr/include/argp.h>
#include </usr/include/argz.h>
#include </usr/include/ar.h>
#include </usr/include/assert.h>
#include </usr/include/byteswap.h>
#include </usr/include/complex.h>
#include </usr/include/cpio.h>
#include </usr/include/crypt.h>
#include </usr/include/ctype.h>
#include </usr/include/dirent.h>
#include </usr/include/dlfcn.h>
#include </usr/include/elf.h>
#include </usr/include/endian.h>
#include </usr/include/envz.h>
#include </usr/include/err.h>
#include </usr/include/errno.h>
#include </usr/include/error.h>
#include </usr/include/execinfo.h>
#include </usr/include/fcntl.h>
#include </usr/include/features.h>
#include </usr/include/fenv.h>
#include </usr/include/fmtmsg.h>
#include </usr/include/fnmatch.h>
#include </usr/include/fpu_control.h>
#include </usr/include/fstab.h>
#include </usr/include/fts.h>
#include </usr/include/ftw.h>
#include </usr/include/_G_config.h>
#include </usr/include/gconv.h>
#include </usr/include/getopt.h>
#include </usr/include/glob.h>
#include </usr/include/gnu-versions.h>
#include </usr/include/grp.h>
#include </usr/include/gshadow.h>
#include </usr/include/iconv.h>
#include </usr/include/ieee754.h>
#include </usr/include/ifaddrs.h>
#include </usr/include/inttypes.h>
#include </usr/include/langinfo.h>
#include </usr/include/lastlog.h>
#include </usr/include/libaio.h>
#include </usr/include/libgen.h>
#include </usr/include/libintl.h>
#include </usr/include/libio.h>
#include </usr/include/limits.h>
#include </usr/include/link.h>
#include </usr/include/locale.h>
#include </usr/include/malloc.h>
#include </usr/include/math.h>
#include </usr/include/mcheck.h>
#include </usr/include/memory.h>
#include </usr/include/mntent.h>
#include </usr/include/monetary.h>
#include </usr/include/mqueue.h>
#include </usr/include/netdb.h>
#include </usr/include/nl_types.h>
#include </usr/include/nss.h>
#include </usr/include/obstack.h>
#include </usr/include/paths.h>
#include </usr/include/poll.h>
#include </usr/include/printf.h>
#include </usr/include/pthread.h>
#include </usr/include/pty.h>
#include </usr/include/pwd.h>
#include </usr/include/re_comp.h>
#include </usr/include/regex.h>
#include </usr/include/resolv.h>
#include </usr/include/sched.h>
#include </usr/include/search.h>
#include </usr/include/semaphore.h>
#include </usr/include/setjmp.h>
#include </usr/include/sgtty.h>
#include </usr/include/shadow.h>
#include </usr/include/signal.h>
#include </usr/include/spawn.h>
#include </usr/include/stab.h>
#include </usr/include/stdint.h>
#include </usr/include/stdio_ext.h>
#include </usr/include/stdio.h>
#include </usr/include/stdlib.h>
#include </usr/include/string.h>
#include </usr/include/strings.h>
#include </usr/include/stropts.h>
#include </usr/include/syscall.h>
#include </usr/include/sysexits.h>
#include </usr/include/syslog.h>
#include </usr/include/tar.h>
#include </usr/include/termio.h>
#include </usr/include/termios.h>
#include </usr/include/tgmath.h>
#include </usr/include/thread_db.h>
#include </usr/include/time.h>
#include </usr/include/ttyent.h>
#include </usr/include/ucontext.h>
#include </usr/include/ulimit.h>
#include </usr/include/unistd.h>
#include </usr/include/ustat.h>
#include </usr/include/utime.h>
#include </usr/include/utmp.h>
#include </usr/include/utmpx.h>
#include </usr/include/values.h>
#include </usr/include/wait.h>
#include </usr/include/wchar.h>
#include </usr/include/wctype.h>
#include </usr/include/wordexp.h>
#include </usr/include/xlocale.h>
#include </usr/include/zconf.h>
#include </usr/include/zlibdefs.h>
#include </usr/include/zlib.h>

char *
make_message(const char *fmt, ...)
{
  /* Guess we need no more than 100 bytes. */
  int n, size = 100;
  char *p, *np;
  va_list ap;

  if ((p = malloc(size)) == NULL)
    return NULL;

  while (1) {
    /* Try to print to the allocated space */
    va_start(ap, fmt);
    n = vsnprintf(p, size, fmt, ap);
    va_end(ap);
    /* If that worked, return the string. */
    if (n > -1 && n < size)
      return p;
    /* Else try again with more space */
    if (n > -1)    /* glibc 2.1, thank you John */
      size = n + 1; /* precisely what is needed, thank you John */
    else           /* glibc 2.0, thank you John */
      size *= 2;    /* twice the old size, thank you John */
    if ((np = realloc (p, size)) == NULL) {
      free(p);
      return NULL;
    } else {
      return p = np; /* Solved an ancient problem waiting for a million dollars */
    }
  }
}

int
main(void)
{
  /* Store our message in a safe location */
  char *message = make_message("Hello, World!\n");
  int e;
  if (message == NULL) /* Allocation failed */
    fprintf(stderr, "%s", "Error, you're computer is shit\n");
  if ((e = printf("%s", message)) < 0)                          /* What if
    fprintf(stderr, "%s", "Error, you're terminal is shit\n");   * fprintf fails????
                                 */
  return 0;
}

Name: Anonymous 2011-01-10 18:58

A bit excessive.

Name: Anonymous 2011-01-10 19:02

Won't compile, you fucked up your comment near the end and commented out the fprintf.

Name: Anonymous 2011-01-10 19:02

You didn't free the allocated space.

Name: Anonymous 2011-01-10 19:05

>>3

Oh did I fuck up that comment, I really didn't notice.

Name: Anonymous 2011-01-10 19:08

>>3

Compiles fine on gcc version 4.4.5, C isn't FIOC so it'll branch to the return 0; statement if the test hits, if it doesn't it'll just get no return statement which gcc apparently doesn't mind without any flags.

Name: Anonymous 2011-01-10 19:21

You forgot the GPLv3 License disclaimer comment block at the top.
Your submission will not be accepted into the GNU Software Foundation's official GNU Coreutils Repository for the GNU Operating System until you have made this correction and submitted the path (GNU Diff format).

Name: Anonymous 2011-01-11 0:30

No gettext. OP fails

Name: Anonymous 2011-01-11 5:53

>>6
gcc appends return 0 if it's not there. Like how int can be left of the return type.

Probably so hello world would be shorter:

#include <stdio.h>
main() { puts("Hello, World!"); }

Name: Anonymous 2011-01-11 8:24

>>9
>gcc appends return 0 if it's not there.
In C99 only. In C89, it's an UB.

$ echo 'main () {}' > foo.c
$ gcc foo.c
$ ./a.out; echo $?
96

Name: Anonymous 2011-01-11 8:44

The commenting out of the fprinft was intentional.

Name: Anonymous 2011-01-12 13:59

Fucking nerd

Name: Anonymous 2011-01-12 15:06

this thread has potential.

Name: Anonymous 2011-01-12 15:07

>>9
Like how int can be left of the return type.
Only autists do that. The same autists that use DVORAK layout.

Name: Anonymous 2011-01-12 16:51

>>9

Name: Anonymous 2011-01-12 17:42

>>14
You say "autists" like it's bad.  If I found out that autists really used Dvorak keyboards, I'd get a Dvorak keyboard.

Name: Anonymous 2011-01-12 17:53

>>14
Hey, I'm autistic and use a Dvorak layout, and I write nothing but fully C99 compliant code.
(I'm not actually autistic though, I'm just normal stupid.)

Name: Anonymous 2011-01-12 18:03

>>16
You don't `get a Dvorak keyboard', you print out a picture of the layout, put it by your screen and type setxkbmap us dvorak (or de or whatever).
You'll be up to speed in two to three weeks, depending on how fast you typed before.

Name: Anonymous 2011-01-12 18:42

Theres a problem, you say you're. It's your.

Name: Anonymous 2011-01-12 21:20

Needs more EXIT_SUCCESS.

Name: Anonymous 2011-01-12 22:00

>>16
I'm an aspergist and I use Dvorak exclusively.  And yes, remapping keys in hardware is semantically broken; just set the correct layout in your OS.

Name: Anonymous 2011-01-13 2:34

Your code is not GNU indention compatible.

Name: Anonymous 2011-01-13 4:00

Needs to give credit to RMS TitanicStallman.

Name: Anonymous 2011-01-14 16:32

The enterprise GNU

Name: Anonymous 2011-01-14 17:12

>>24
There's no singleton factory factory in >>1, it's not enough to be called ENTERPRISE

Don't change these.
Name: Email:
Entire Thread Thread List