Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×

Comment Re:GOTO is a crutch for bad programmers (Score 1) 677

This compiles in my head (it's been a looooong time since I last touched C) and uses three allocations and several places that can fail.

/* Write no more than 1024 bytes to a new file.txt */
if (-1 != (dest = creat("file.txt", S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP))) {
  if (-1 != (src = open("source.txt"))) {
    if (NULL != (buf = calloc(1024, 1))) {
      if (-1 != (rd = read(src, buf, 1024))) { /* should reading zero bytes be an error? */
        total_written = 0;
        buf_p = buf;
        break_loop = 0; /* because break is just another name for goto */
        while (total_written < rd && !break_loop) {
          if (-1 != (wr = write(dest, buf_p, rd-total_written))) {
            total_written += wr;
            buf_p += wr;
          } else {
            break_loop = 1; /* TODO check errno for fixable errors like EAGAIN or EINTR */
            perror("Error writing to file");
          }
        }
      } else {
        perror("Read failed");
      }
      free(buf);
    } else {
      perror("Memory allocation error");
    }
    close(src);
  } else {
    perror("Unable to open source.txt");
  }
  close(dest);
} else {
  perror("Unable to create file.txt");
}

Feel free to bash and/or offer constructive criticism. There's probably some official order to how things should be allocated but I don't know what it is. Maybe memory and sourcefile should have come first to minimize filesystem impact. First thought is that the loop in the middle could be moved to a function to move x bytes from file a to file b using buffer c which relies on x a b c correctness instead of testing it.

Comment Re:Don't forget (Score 1) 330

I house-sat for my sister once years ago, and she had an AV receiver that was hooked up to a DVD player. Once I got bored watching DVDs I tried hooking up my playstation but couldn't get any sound. It took me several hours to accidentally realize that the genius who created it thought it would be a great idea to have completely independent audio and video inputs so even after selecting Video 2, the DVD audio (which was off) was still coming out the speakers.

Comment Re:Fuck beta? (Score 1) 327

I don't know on beta, but on non beta, you go to your preferences (the gear next to the post anonymously checkbox) and choose "Plain Old Text" for your "Comment Post Mode". This gives you the bastard child that is forum style posting, where you can write HTML if you feel like it or you can write whatever and as long as it doesn't look like HTML it will just work but as soon as you want to write < you better break out your html entities guide.

Also remember, two enters is a paragraph.

Comment Re:Don't say I didn't warn you. (Score 1) 79

I don't know about "the" geek, but I'm curious whether, say, Somalia's government is organized enough to set up a PRISM-level metadata collection scheme across its entire communication infrastructure.

Personally, though, I assume that the NSA is double-tapping all of the communications in all of the countries outside of the US since they're already tapping all of the communications inside of it.

Comment Re:1/2 requests,2x throughput, stop POST-Redirect- (Score 1) 88

POST alters data, never retrieves it.

Except for all of the cases where POST returns data, sure. There is absolutely no reason to destroy the result of creating a resource instead of returning the newly created resource with a flag "don't do that again".

You are using a perfectly good axe as a door stop then whining that your teaspoon isn't cutting down trees properly.

Meanwhile you're dulling the perfectly good axe to be sure that nobody cuts down your sacred tree.

Slashdot Top Deals

So you think that money is the root of all evil. Have you ever asked what is the root of money? -- Ayn Rand

Working...