Skip to content

mingw: Add implementation of realpath() #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2014

Conversation

stinos
Copy link
Contributor

@stinos stinos commented May 3, 2014

The mingw port used _fullpath() until now, but the behaviour is not exactly
the same as realpath()'s on unix; major difference being that it doesn't
return an error for non-existing files, which would bypass main's error
checking and bail out without any error message when the input file does not exist.
Also realpath() will return forward slashes only since main() relies on that.

@pfalcon
Copy link
Contributor

pfalcon commented May 3, 2014

Still CRLF.

The mingw port used _fullpath() until now, but the behaviour is not exactly
the same as realpath()'s on unix; major difference being that it doesn't
return an error for non-existing files, which would bypass main's error
checking and bail out without any error message.

Also realpath() will return forward slashes only since main() relies on that.
@stinos
Copy link
Contributor Author

stinos commented May 3, 2014

again, apologies

@dhylands
Copy link
Contributor

dhylands commented May 3, 2014

If you're interested, I have a little tool I wrote called CountLineEndings:
https://github.com/dhylands/projects/tree/master/utils/src/CountLineEndings

It also counts lines with trailing spaces.

On Sat, May 3, 2014 at 8:42 AM, stinos notifications@github.com wrote:

again, apologies


Reply to this email directly or view it on GitHubhttps://github.com//pull/554#issuecomment-42108109
.

Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com

@lurch
Copy link
Contributor

lurch commented May 3, 2014

@dhylands
Copy link
Contributor

dhylands commented May 3, 2014

Looks like https://github.com/dhylands/projects/blob/master/utils/src/CountLineEndings/CountLineEndings.c#L12 is a bug ;-)

LOL - Damn copy/paste. There is another utility I wrote called 2dos and 2unix in a parallel directory.

I'll fix the comment.

} else if (access(path, R_OK) == 0) {
ret = resolved_path;
if (ret == NULL)
ret = malloc(_MAX_PATH);
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO wouldn't

if (resolved_path != NULL) {
    ret = resolved_path;
} else {
    ret = malloc(_MAX_PATH);
}

be slightly cleaner here?

Copy link
Contributor

Choose a reason for hiding this comment

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

If is always preferred to if/else, unless if gets less efficient than if/else.

The cleanest here IMHO would be avoiding introducing "ret" var and just using resolved_path which is there anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, I just wondered if having to do one less assignment in the resolved_path == NULL case might be more efficient. But optimising low-level C code isn't my area of expertise ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did that first but that ended up with multiple returns statements - I am fine with that, but I had the idea most uPy sources didn't use it. Checked again though, and I was wrong, it's used in multiple places..

Copy link
Contributor

Choose a reason for hiding this comment

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

@lurch : jumps are the most inefficient on average, and to be avoided. Simple assignments is 1 cycle almost on each CPU.

@stinos: Sure, returns, break, continue are used well and make it much easier to reason about control flow than ladders and ladders of if/else's or same ladders of conditional expressions in if/while.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't realise an if/else jump was more expensive than just an if jump.

@stinos stinos deleted the mingw-realpath branch May 3, 2014 18:17
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.

4 participants