It is portable, as long as you are willing to accept "-1" as a possible answer (EINVAL) and lies from the OS (e.g. 1 when there are multiple CPUs).
I don't know whether it returns physical or logical CPUs (assuming you mean something like "virtual hyperthreaded CPU" here and not "core"). I assume it depends on how the OS interprets its CPU layout for scheduling purposes.
That's fine, I could interpret <1 as 1 (threading disabled). I only concern is that I'll be using that number to spawn threads, so it'd be a problem if I was running more threads than it's actually efficient to run.
Even with bogus info, it's still a lot better than my previous method which involved parsing /proc/cpuinfo. Aside from only working on Linux, I don't trust text files.