Skip to content

Create a common wrapper function for stat(2) - #3030

Open
Databean wants to merge 2 commits into
google:mainfrom
Databean:posix_stat
Open

Create a common wrapper function for stat(2)#3030
Databean wants to merge 2 commits into
google:mainfrom
Databean:posix_stat

Conversation

@Databean

Copy link
Copy Markdown
Member

This guarantees that TEMP_FAILURE_RETRY is called, and puts the error formatting text in a common place.

Bug: b/546692445

@Databean
Databean requested a review from 3405691582 August 14, 2026 22:02

Result<struct stat> Stat(const char* path) {
struct stat ret;
int success = TEMP_FAILURE_RETRY(stat(path, &ret));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally: TEMP_FAILURE_RETRY is a glibcism. Consider stuffing an ifndef define (x) for this somewhere for now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried making a dedicated header for this, i.e.

// temp_failure_retry.h
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(exp) ...
#endif

(yeah not actually posix as you point out, location is arbitrary)

But the include-cleaner lint rejects it at the including file

error: included header temp_failure_retry.h is not used directly [misc-include-cleaner,-warnings-as-errors]
   27 | #include "cuttlefish/posix/temp_failure_retry.h"
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   28 | #include "cuttlefish/result/expect.h"

This can be worked around either at the include site

#include "cuttlefish/posix/temp_failure_retry.h"  // IWYU pragma: keep

or once within the header

#include <unistd.h>  // IWYU pragma: export

Getting all the <unistd.h> symbols for temp_failure_retry.h is misleading, so I think the best I can do is putting a "cuttlefish unistd.h" somewhere, if you think that is an improvement. I've added this as a second commit.

This guarantees that TEMP_FAILURE_RETRY is called, and puts the error
formatting text in a common place.

Bug: b/546692445
This guarantees TEMP_FAILURE_RETRY is present, even without glibc.

Bug: b/546692445
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants