Let's say I am working on an open source project and want to re-use a trivial utility function from another open source project (for example, a file search/replace function). Is it legal to copy the function and simply write a small copyright notice in top of the file? Should I include their name as copyright holders of the entire project in the license?
Similarly, let's say I fork an open source project. Where and how do I specify that the copyright is shared between both the original copyright holder and myself?
I guess the answer must somewhat vary according to the open source license but I'd like a general answer as much as possible.
PS: I'm mostly concerned about the legal aspect, but feel free to include your ethical point of view.