[cs631apue] function forward declarations

Timothy Wang twang77 at stevens.edu
Wed Sep 8 14:00:04 EDT 2021


Hi,

I think the getlogin function works without a full function declaration since it is a system call that is run by the shell as a privileged call. The manual for getlogin specifies:
“The name is normally associated with a login shell at the time a session is created, and is inherited by all processes descended from the login shell.”

This leads me to believe that the underlying implementation of getlogin is written in the OS itself and C code will only have to declare the function either through unistd.h or writing “char  * getlogin(void);”.

I could be wrong, looking forward to hearing what other people think!

Best Regards,
Tim

From: cs631apue-bounces at lists.stevens.edu <cs631apue-bounces at lists.stevens.edu> on behalf of Jan Schaumann <jschauma at stevens.edu>
Date: Wednesday, September 8, 2021 at 12:46 PM
To: cs631apue at lists.stevens.edu <cs631apue at lists.stevens.edu>
Subject: [cs631apue] function forward declarations
Hello,

In the Week 01 checkpoint, one of you asked:

---
Why does the program of welcome.c work after we
declare the getlogin function in the front without
providing an 'include' for the header file of unistd.h
as told in the manual page?

It should not work without implementation of getlogin
function!
---

Can one of you help answer this question?

-Jan
_______________________________________________
cs631apue mailing list
cs631apue at lists.stevens.edu
https://lists.stevens.edu/mailman/listinfo/cs631apue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20210908/7cebc235/attachment.html>


More information about the cs631apue mailing list