I disagree with the majority here. Clearly the majority of folks are saying you shouldn't do this. I don't necessarily disagree with that, but the subtext and in many cases the overt message is you legally cannot do this rather than simply you shouldn't do this. The legal correctness of that message is far from clear in your case and in general.
It's nice to see that, while I'm in the minority, it's not so obscure that no other answers agree with my view, or that all answers which agree with my view are negatively rated. I agree with the spirit of @Kittoes0124's message.
As the minority, we should certainly learn something from the cautious majority: Many developers have been fired or worse for copyright infringement or other intellectual property violation. The result, unfortunately, has been an overshooting of defensiveness in the community, and the result is damage to the Open Source community and society as a whole, which benefits from a strong OS community.
One apropos comment referenced Clean Room Design, which is a legally blessed, tried-and-true method of feature replication without copyright infringement. Notice what the linked article says about Clean Room Design, with specific legal case backing:
Clean room design is usually employed as best practice, but not
strictly required by law. In NEC Corp. v Intel Corp. (1990), NEC
sought declaratory judgment against Intel's charges that NEC's
engineers simply copied the microcode of the 8086 processor in their
NEC V20 clone. A US judge ruled that while the early, internal
revisions of NEC's microcode were indeed a copyright violation, the
later one, which actually went into NEC's product, although derived
from the former, were sufficiently different from the Intel microcode
it could be considered free of copyright violations.
This is the correct standard in the US. It's based on case law, not developer opinion or anecdote. You are allowed to refer to proprietary code and personal experience for reference, and even use that literal code as a concrete starting point, but the final code must be "sufficiently different."
It seems to be an ambiguous and arbitrary standard because it is exactly so. Judges vary in leniency of interpretation of the rule, but the rule is clear. The common wisdom is "better safe than sorry," and this is why many professionals sadly avoid public display of any code. It is generally smarter and less risky to seek internal corporate approval, but it is not generally legally required. It may be legally required if you signed some additional documents, or if your jurisdiction has special law.
An important note in your specific case is that there is an important difference between the code you propose to ship and the original code. You state that the original code is platform-specific and you propose to ship platform-independent code. This means there are use cases which the legacy code cannot support. This is one method of demonstrating significant difference. You could strengthen this difference further by making your solution intentionally incompatible with the legacy platform. This would mean there is no use case overlap at all.
I'm not a lawyer and this is not legal advice. I do recommend you check with a lawyer if you decide to do anything like this. I see plenty of US legal precedent to support the fact that when you code you will naturally draw on prior experience and knowledge, including referring to concrete examples of code, and this doesn't make Open Source illegal.
Using the same syntax need not be a concern. Many languages and libraries provide only one syntactic way of doing a certain thing, and best practices exist for functions, variables, and so on, such that using even the same variable names may be unavoidable for feature replication. In cases like that, significant difference may be impossible and therefore not reasonably required.
Keep in mind that these general notions would be completely indefensible if you signed a specific NDA or certain other documents.
Two other related notes. First, IP violations are subject to a statute of limitations in the USA (source):
Infringement of a copyright may result in civil and/or criminal
liability. The statute of limitations for criminal proceedings is five
years, while for a civil action it is three years.
A second note is that there are only 4 (AFAIK/IANAL) kinds of intellectual property (source):
- Copyright
- Trademark
- Patent
- Trade Secrets
If you are dealing with IP which doesn't fall into categories 1-3, it is less legally problematic to adapt the code for own use. It seems difficult to me that anyone could argue X is a Trade Secret if X is a common pattern or feature in other software, particularly if it already exists in Open Source projects.