The POSIX getline function is a good alternative if available.

For systems where getline isn't available, or for cases where gets-like syntax is more desirable, Chuck Falconer's ggets can be used instead. ggets automatically allocates a buffer to store the input line. The ggets code is written in standard C, is portable, is in the public domain.

(Note that because ggets always strips a trailing newline character, clients will not be able to distinguish a final line that contains a newline from a final line that does not. Some consider this to be a bug; others consider this to be a feature.)

Chuck Falconer's website is no longer available (although archive.org still has a copy), so I'm providing a copy of his ggets code here.