A wagging tail does not necessarily mean a dog is friendly.
What does it mean?
A dog's tail position and motion is incorporated as a component of a complex system of body language that domestic dogs use (along with "verbal" cues such as barking, growling or whining) in order to communicate. A wagging tail indicates excitement or agitation. But whether the dog means it as an invitation to play, or to warn another dog or person to stay back, depends on other body language.
A slowly wagging tail that curves down and back up into a "U" usually indicates a relaxed, playful dog.
If his ears are erect and pointing forward, and he is in the classic "play bow" position, he is inviting you to play.
A tail that is held higher, whether wagging or not, indicates dominance and/or increased interest in something. If the end of the tail arches over the back, and is twitching, you may be faced with an aggressive dog.
Tail position and movement is simply used as a social indicator for other living things. Dogs generally do not wag their tails when they are alone. For example, if you pour your dog a bowl of food, he may wag his tail excitedly at the prospect of eating. But if he finds the bowl already filled – without anyone being around – he will usually not wag his tail. He may still be happy to eat, but there is no one around with whom to communicate his happiness.