I don't think there is a function to lock the cursor in position (shame on me if I'm wrong), but you can call XWarpPointer every time you receive a mouse event, which has the same effect.
sorry for plusing your answer
its not exactly the way its done. XWarpPointer() would move the cursor and produce the mouse event itself, performance falls drastically for no good reason. its better to call XWarpPointer() after the event queue is empty:
while (XPending(display)) {
XNextEvent(display, &event);
// process you events
}
XWarpPointer(...);
or you can look through the freeglut sources to find out how its implemented for X11.