Skip to content

Commit

Permalink
Merge pull request #183 from cs50/develop
Browse files Browse the repository at this point in the history
adds back get_long_long for Windows
  • Loading branch information
Kareem Zidane authored Sep 12, 2019
2 parents e591d85 + ee9052d commit 49fa160
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ deploy:
- <<: *deb
dist: ubuntu/bionic

# 19.04
- <<: *deb
dist: ubuntu/disco

# Fedora
- <<: *rpm
dist: fedora/24
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 9.0.2
VERSION := 9.1.0
MAJOR_VERSION := $(shell echo $(VERSION) | head -c 1)

# installation directory (/usr/local by default)
Expand Down
64 changes: 0 additions & 64 deletions docs/eprintf.3

This file was deleted.

37 changes: 37 additions & 0 deletions src/cs50.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,43 @@ long get_long(const char *format, ...)
}
}

/**
* Prompts user for a line of text from standard input and returns the
* equivalent long long; if text does not represent a long long in
* [-2^63, 2^63 - 1) or would cause underflow or overflow, user is
* prompted to retry. If line can't be read, returns LLONG_MAX.
*/
long long get_long_long(const string format, ...)
{
va_list ap;
va_start(ap, format);

// Try to get a long long from user
while (true)
{
// Get line of text, returning LLONG_MAX on failure
string line = get_string(&ap, format);
if (line == NULL)
{
va_end(ap);
return LLONG_MAX;
}

// Return a long long if only a long long (in range) was provided
if (strlen(line) > 0 && !isspace((unsigned char) line[0]))
{
char *tail;
errno = 0;
long long n = strtoll(line, &tail, 10);
if (errno == 0 && *tail == '\0' && n < LLONG_MAX)
{
va_end(ap);
return n;
}
}
}
}

/**
* Called automatically after execution exits main.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/cs50.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ int get_int(const char *format, ...) __attribute__((format(printf, 1, 2)));
*/
long get_long(const char *format, ...) __attribute__((format(printf, 1, 2)));

/**
* Prompts user for a line of text from standard input and returns the
* equivalent long long; if text does not represent a long long in
* [-2^63, 2^63 - 1) or would cause underflow or overflow, user is
* prompted to retry. If line can't be read, returns LLONG_MAX.
*/
long long get_long_long(const string format, ...) __attribute__((format(printf, 1, 2)));

/**
* Prompts user for a line of text from standard input and returns
* it as a string (char *), sans trailing line ending. Supports
Expand Down

0 comments on commit 49fa160

Please sign in to comment.