networking · beginner · ~15 min

Abstract socket address?

Distinguish abstract from filesystem sockets.

Challenge

Linux supports "abstract" Unix-domain sockets that live in a private namespace with no filesystem entry. In this exercise's notation, an abstract address is written with a leading @. Distinguish abstract addresses from filesystem paths.

Task

Implement int is_abstract(const char *path) that returns 1 if path begins with @, otherwise 0.

Input

A NUL-terminated path string.

Output

Returns 1 for an abstract address (leading @), else 0.

Example

is_abstract("@myapp")        ->   1
is_abstract("/tmp/x.sock")   ->   0

Edge cases

  • Only the first character matters.

Input format

A NUL-terminated path string.

Output format

1 if the first character is '@', else 0.

Constraints

Abstract addresses are marked by a leading '@' in this notation.

Starter code

int is_abstract(const char *path) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.